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,
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With