Search code examples
swiftxcode6nsdatenscalendar

Create own NSDate


I would like to create an NSDate. It should be the year 1, the month 1, the day 1, the minute 0, the seccond 0 and the nanoseccond 0. I don not know how I can create this day myself. So do you guys know how to do this in Swift? Thanks a lot for your help!


Solution

  • That can be done by using NSDateComponents

    var dateComponents = NSDateComponents()
    dateComponents.second  = 0
    dateComponents.minute = 0
    dateComponents.hour = 0
    dateComponents.day = 1
    dateComponents.month = 1
    dateComponents.year = 1
    dateComponents.nanosecond = 0
    let date = NSCalendar.currentCalendar().dateFromComponents(dateComponents)