我想获得 UTC 时间戳。我不能像这样 [[NSDate date] timeIntervalSince1970];
因为它返回本地时区的时间戳。如何在 iOS 中获取 UTC 时间戳?
编辑
解决了我可以使用[[NSDate date] timeIntervalSince1970];
:)
最佳答案
在这里查看 Pawel 的回答:Get current date in milliseconds
他指的是使用 CFAbsoluteTimeGetCurrent();
已记录 here .
因为它是系统时间,只需更正与 GMT 的时间间隔偏移即可。
不过,如果您更正本地时区,使用您的代码也同样有效。
您可以通过调用获得时区偏移量
[[NSTimeZone systemTimeZone] secondsFromGMT];
或
[[NSTimeZone systemTimeZone] secondsFromGMTForDate:[NSDate date]];
关于iOS获取UTC时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22070632/