timeIntervalSinceReferenceDate -- how does it keep track?

Discussion in 'iOS Programming' started by milktooth, Nov 14, 2009.

  1. milktooth macrumors member

    Oct 30, 2009
    [NSDate timeIntervalSinceReferenceDate]

    Does the device keep track of this internally or is there a server that updates timeIntervalSinceReferenceDate?
  2. neoserver macrumors 6502

    Apr 24, 2003
    Its kept track of internally. The time stored is the number of seconds from January 1st, 2001.
  3. milktooth thread starter macrumors member

    Oct 30, 2009
    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?
  4. neoserver macrumors 6502

    Apr 24, 2003
    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.
  5. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    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.

Share This Page