Converting JSON date(ticks) to NSDate

Zap picture Zap · Aug 12, 2009 · Viewed 9.1k times · Source

Does anyone know how to convert a JSON date(ticks) to an NSDate in Objective-C? Can someone post some code?

Answer

Marc Charbonneau picture Marc Charbonneau · Aug 12, 2009

I'm guessing here but your JSON value is the number of milliseconds since 1970, right? You can use NSDate's dateWithTimeIntervalSince1970: method to return an NSDate object with the correct time. Just make sure to convert the JSON milliseconds number to seconds before passing it to NSDate-- Cocoa uses NSTimeInterval in most places, which represents an interval in seconds.