iOS获取UTC时间戳

标签 ios objective-c swift date timestamp

我想获得 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/

相关文章:

ios - Apple 的 Cloudkit 迁移

ios - 在点击 map 注释图钉时执行 segue

关于字体大小的 iOS 9 问题

iphone - 比较两个 nsdatecomponents

ios - 沿路径的 SceneKit 动画节点

ios - DispatchGroup 未按预期工作

ios - 如何使用 AVPlayer addperiodictimeobserverforinterval 函数更新 uilabel?

ios - AnyObject 上的算术运算失败

html - 当我使用 wkwebview 加载本地 html 时,我发现它呈现速度比 uiwebview 慢

ios - 检测点击 UITabBarController 中的选项卡