Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

milktooth

macrumors member
Original poster
Oct 30, 2009
32
0
[NSDate timeIntervalSinceReferenceDate]

Does the device keep track of this internally or is there a server that updates timeIntervalSinceReferenceDate?
 
Its kept track of internally. The time stored is the number of seconds from January 1st, 2001.
 
So, no matter whether the device is online or not, the value will always be the same? What happens if the battery dies? Is it accurate after a recharge?
 
The value returned is based upon the time that is set on the device. I unfortunately don't know what happens in the event that the battery completely dies. I know that if it is an iPhone the time will be re-synced by the cell network, as for an iPod I suspect the next time it is connected to a computer the time will be re-synced as well. I know for a fact that as long as there is battery power the time will be kept up-to-date even if the device has been turned off.

I should also mention that this value is not a constant, but rather another way to measure the current time. the value returned is the current date and time as the number of seconds that have elapsed since Jan. 1 2001. Just to emphasize, this value is 100% dependant on the time set on the device and therefore will only be as accurate as that. There is no way to ensure that the time set on the device is 100% accurate but one can probably safely assume that it will be relatively so.
 
[NSDate timeIntervalSinceReferenceDate]

Does the device keep track of this internally or is there a server that updates timeIntervalSinceReferenceDate?

Yes. Both. Or all three.

Three? Or more... There's usually a fast clock that runs when the device is on, this fast clock gets updated from a slow clock that runs even when the device is off, and an OS service that periodically updates both these clocks from either a network time server or from a cell towers clock.

The fast clock may jump around if/when updated from the slow clock, the slow clock may jump around if/when updated from the cell tower, and the cell towers clock can jump around when updated from a network time server. The network time servers are atomic clocks that get adjusted so gradually that you'd never notice, except when they add lead seconds every so often, then even they jump around.

If you want accurate time, you use the fast clock, but calibrate it against the network clock over a long period, and compensate for drift and updates, and hope the temperature doesn't change too much, which will throw off your calibration.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.