3

In core motion, data is returned in a class inheriting from CMLogItem, which has a timestamp property. The timestamp is a TimeInterval that is the time since the device booted.

How do I get when the device booted?

Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
  • 1
    [This question](https://stackoverflow.com/questions/6911226/nslog-timestamp) has an answer by @gros with a good approach. The answer is in Objective-C, but it shouldn’t be too hard to convert; basically assume that the first update is delivered close enough to “now” that you can subtract the timestamp from “now” to get the boot time. – Paulw11 Sep 25 '17 at 22:45
  • [`CACurrentMediaTime()`](https://developer.apple.com/documentation/quartzcore/1395996-cacurrentmediatime) returns the [`mach_absolute_time`](https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time), which is the time since reboot, and `CACurrentMediaTime` does the conversion to seconds for you. – Rob Sep 25 '17 at 23:18

1 Answers1

5

From the comments, I was able to find ProcessInfo.processInfo.systemUptime which is the time since last boot. From this, and Date(), I can get the time of start via:

time_of_last_boot = Date() - ProcessInfo.processInfo.systemUptime
Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
  • This is not correct. See this answer: https://stackoverflow.com/a/23508656/1226963 and the comments below it. Then review the other answers. – rmaddy Nov 11 '18 at 16:34