[NSDate日期]是如何计算的?
我在 Web 服务器上的方案中使用当前日期的一部分,并且希望在设备上生成与服务器上相同的值。理论上,我考虑了这两个值不相同并且两端的值不匹配的情况。
这让我思考 - 具体来说,当应用程序运行时,[NSDate date]
是如何计算的?
编辑:我想我真正要问的是,iPhone如何从权威来源获取时间?它似乎来自我认为的手机信号塔都以某种方式同步。这是真的吗?
编辑:看起来它使用了 gettimeofday(),它使用系统时钟。从 Apple 文档来看,当您将 iPhone 设置为“自动设置”时,它会使用蜂窝网络上的正确时间。
谢谢,
I'm using part of the current date in a scheme on a web server and I want to generate the same value on the device as on the server. In theory I thought about a case where these two values wouldn't be the same and the values on either end wouldn't match.
Which then led me to think - how, specifically, is [NSDate date]
calculated when an app is running?
Edit: I guess what I'm really asking, is how does an iPhone get its time from an authoritative source? It appears it comes from a cell tower which I would assume are all synced somehow. Is this true?
Edit: Looks like it uses gettimeofday() which uses the system clock. And from Apple docs, looks like when you have the iPhone set to 'Set Automatically', it uses the correct time over the cell network.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以通过在调试器中逐步执行或简单地对调用堆栈进行采样来找出答案。
它使用
gettimeofday
。因此,您不能期望该值在两个设备上相等或完全同步。
you can find out by stepping through in the debugger or simply sample it for the callstacks.
it uses
gettimeofday
.as such, you can't expect this value to be equal or perfectly synchronized on two devices.