zumzum zumzum - 1 year ago 129
Swift Question

NSDate timeIntervalSince1970 not working in Swift?

I am doing this in swift:

let date = NSDate(timeIntervalSince1970: 1432233446145.0)
println("date is \(date)")

The log gives me this:

date is 47355-09-02 23:55:45 +0000

Then I try to get an interval back out just for testing:

let tI = expirationDate.timeIntervalSinceDate(date)
println("tI = \(tI)")

I get:

tI = 0.0

What am I doing wrong?
I can seem to make the timeIntervalSince1970 call work properly. Is there any known issued with that in Swift, or am I missing something here?

Answer Source

1432233446145 most probably is a time interval given in milliseconds:

let date = NSDate(timeIntervalSince1970: 1432233446145.0/1000.0)
print("date is \(date)")
// date is 2015-05-21 18:37:26 +0000

(Even if that does not immediately explain why tI is zero in your case, it should help to localize the actual problem.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download