Converting JSON date(ticks) to NSDate

后端 未结 4 1935
误落风尘
误落风尘 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条回答
  •  梦谈多话
    2021-01-21 09:07

    You'd have to detect the client's locale in order to be able to do that, and unless your client knows how to do that, there's probably not much point.

    NSDate's descriptionWithLocale: would be the way you format it for another locale. And timeIntervalSince1970 will go back to the (seconds) since 1970, which you could multiply by 1000 to get ms to return to the client. It's all in the NSDate documentation.

    http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html

提交回复
热议问题