将时间戳转换为nsdate格式 [英] converting timestamp to nsdate format
本文介绍了将时间戳转换为nsdate格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将时间戳值 1308031456
转换为 NSDate
格式(产生值 Tue,2011年6月14日06:04:16 GMT
在线网络转换)。如何以编程方式在两者之间进行转换?
I want to convert my timestamp value 1308031456
to NSDate
format (which yields the value Tue, 14 Jun 2011 06:04:16 GMT
in online web conversion). How would I convert between the two programmatically?
推荐答案
OBJ - C:
使用 dateWithTimeIntervalSince1970:,
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];
SWIFT:
使用 init(timeIntervalSince1970:)
let date = NSDate(timeIntervalSince1970:timeStamp)
这篇关于将时间戳转换为nsdate格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文