How is [NSDate date] calculated?

I am using part of the current date in a schema on a web server, and I want to generate the same value on the device as on the server. Theoretically, I was thinking about the case when these two values ​​would not be the same, and the values ​​at both ends would not coincide.

What made me think - how exactly is [NSDate date] calculated when the application starts?

Edit: I guess I'm really asking how does the iPhone get its time from a reputable source? It seems to come from a mesh tower, I would suggest that everything is somehow synchronized. It's true?

Edit: It looks like it uses gettimeofday (), which uses the system clock. And from Apple docs , it looks like when you have your iPhone set to “Automatically installed,” it uses the correct time over the cellular network.

Thanks,

+7
source share
3 answers

you can find out by going to the debugger or just scan it for calls.

he uses gettimeofday .

as such, you cannot expect this value to be equal to or perfectly synchronized on two devices.

+3
source

Keep in mind that your application can run on iPod Touch or on a phone that does not have a 3G connection. You get the time that the phone displays on the top panel.

+1
source

UNIX system clock using (as other people have said) gettimeofday() . The phone probably syncs with an NTP server like time.apple.com is what the X desktop OS does.

+1
source

All Articles