How do i convert Date to TimeInterval so I can use the if statements
Swift 3.0
You Need write code this:
let elapseTimeInSeconds = Date().timeIntervalSince(date as Date)
Strong!!! Date() or NSDate().timeIntervalSince(date as Date)
You can directly access it through property timeIntervalSinceNow
of Date
also there is no need to use NSDate
in Swift 3 use directly Date
and date(from:)
method of DateFormatter
return instance of Date?
not NSDate?
.
let timeInterval = date.timeIntervalSinceNow
And you can get TimeInterval
between two dates using method timeIntervalSince(_:)
.
let timeInterval = date1.timeIntervalSince(date2)