Converting JSON date(ticks) to NSDate

后端 未结 4 1860
误落风尘
误落风尘 2021-01-21 08:34

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

4条回答
  •  旧时难觅i
    2021-01-21 09:16

    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.

提交回复
热议问题