Odd thing happening here. The following code:
String(Int(date.timeIntervalSince1970*1000))
works in a playground but doesn't in a class. It crashes with EXC_BAD_INSTRUCTION.
Any ideas why? Alternatively, how do I get a string of the above NSTimeInterval
?
Thanks in advance!
Edit: I need the result as Int, so 1402324472549 and not 1402324472549.64, for example.
Inside a class definition:
var date = NSDate()
let myDateString = String(Int64(date.timeIntervalSince1970()*1000))
println("Seconds = \(myDateString)")
Not sure of the root cause, but it is something to do with the type conversion. This works:
var date = NSDate()
var asString = "\(Int(date.timeIntervalSince1970*1000))"
println(asString)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With