[NSDate日期]是如何计算的?

发布于 12-04 17:04 字数 438 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一个人的旅程2024-12-11 17:04:23

您可以通过在调试器中逐步执行或简单地对调用堆栈进行采样来找出答案。

它使用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.

胡大本事2024-12-11 17:04:23

请记住,您的应用程序可能在 iPod Touch 或没有 3G 连接的手机上运行。无论手机顶部栏显示什么时间,您都可以获取。

Keep in mind that your app may run on an iPod Touch, or on a phone that simply has no 3G connection. You get whatever time the phone is displaying on its top bar.

放肆2024-12-11 17:04:23

UNIX系统时钟,使用(正如其他人所说的)gettimeofday()。手机可能与 NTP 服务器(例如 time.apple.com)同步 - 这就是桌面 OS X 所做的事情。

UNIX system clock, using (as other people said) gettimeofday(). Phone probably synchronizes with an NTP server such as time.apple.com - this is what desktop OS X does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文