Is there an API to obtain the NSDate
or NSTimeInterval
representing the time the system booted? Some APIs such as [NSProcessInfo systemUptime]
and Core Motion return time since boot. I need to precisely correlate these uptime values with NSDate
s, to about a millisecond.
Time since boot ostensibly provides more precision, but it's easy to see that NSDate
already provides precision on the order of 100 nanoseconds, and anything under a microsecond is just measuring interrupt latency and PCB clock jitter.
The obvious thing is to subtract the uptime from the current time [NSDate date]
. But that assumes that time does not change between the two system calls, which is, well, hard to accomplish. Moreover if the thread is preempted between the calls, everything is thrown off. The workaround is to repeat the process several times and use the smallest result, but yuck.
NSDate
must have a master offset it uses to generate objects with the current time from the system uptime, is there really no way to obtain it?
NSDate
is a wall-clock timestamp, and changes such as daylight savings and NTP updates can cause two successive moments in real time to show up in the wrong order asNSDate
s (ortime_t
s or any other wall-clock timestamp.) – ReboantCACurrentMediaTime()
--it's adouble
viaCFTimeInterval
, but it's guaranteed to increase regularly over time and is measured in seconds. – Reboant