iOS UTC秒数时间戳和日期的互相转换[转载]

参考:

iOS UTC秒数时间戳和日期的相互转换【原创】


什么是UTC?
协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC。不属于任意时区

简单介绍了一下,想详细了解的自己百度了。

UTC秒数和日期相互转换,现在直接上代码

NSDate *date = [NSDate date];
NSLog(@"当前日期为:%@",date);
NSTimeInterval timeStamp= [date timeIntervalSince1970];
NSLog(@"日期转换为时间戳 %@ = %f", date, timeStamp);
时间戳转日期 (秒数转日期)
NSString *timeStamp2 = @"1414956901";
long long int date1 = (long long int)[timeStamp2 intValue];
NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:date1];
NSLog(@"时间戳转日期 %@  = %@", timeStamp2, date2);


补充:(该内容为原创,参考苹果官方API)

THREAD SAFETY

On iOS 7 and later NSDateFormatter is thread safe.

On OS X v10.9 and later NSDateFormatter is thread safe so long as you are using the modern behavior in a 64-bit app.

On earlier versions of the operating system, or when using the legacy formatter behavior or running in 32-bit on OS X, NSDateFormatter is not thread safe and you therefore must not mutate a date formatter simultaneously from multiple threads.

翻译为中文为:
线程安全性:
自iOS 7及以后,NSDateFormatter是线程安全的。
自OSX v10.9及以后,NSDateFormatter是线程安全的,只要你所开发的事64位app。
在这些版本之前以及32位OS X上,NSDateFormatter是非线程安全的。因此,你不能同时使formatter在多个线程中进行变化。

关于线程安全的知识,想要了解的请自己百度了。个人认为苹果官方API解释得已经很清楚了,如果有不明白的,可以留言,本人看见留言后,会尽快回复。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值