The interval between the dates in Swift
Forums:
let calendar = NSCalendar.currentCalendar()
let victoryDate = calendar.dateWithEra(1, year: 1945, month: 5, day: 9, hour: 0, minute: 0, second: 0, nanosecond: 0)!
let now = NSDate()
let dayHourMinuteSecond: NSCalendarUnit =
[.Day, .Hour, .Minute, .Year]
let diff = calendar.components(
dayHourMinuteSecond,
fromDate: victoryDate,
toDate: now,
options: [])
let years = diff.year
//years is 70
let days = diff.day
//days is 164
let minutes = diff.minute
//minutes is 15
- Log in to post comments