将JSON日期(滴答)转换为NSDate [英] Converting JSON date(ticks) to NSDate

查看:124
本文介绍了将JSON日期(滴答)转换为NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在Objective-C中将JSON日期(滴答)转换为NSDate吗?有人可以发布一些代码吗?

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

推荐答案

我在这里,但是您的JSON值是自1970年以来的毫秒数,对吗?您可以使用NSDate的dateWithTimeIntervalSince1970:方法返回具有正确时间的NSDate对象.只需确保将JSON毫秒数转换为秒,然后再将其传递给NSDate,Cocoa在大多数地方都使用NSTimeInterval,它表示以秒为单位的间隔.

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.

这篇关于将JSON日期(滴答)转换为NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆