Search code examples
iosaccelerometer

Is CMAccelerometerData event time stamp UTC value?


In iOS, I'm using event time stamp available from the event (CMAccelerometerData*)
I want to know whether its referencing from the year 2001 or 1970?
I couldn't find proper document that explains the time stamp details.


Solution

  • The timestamp provided by CMAccelerometerData is the amount of time in seconds since the phone booted.

    So you first have to get phone's boot time, like this:

    let bootTime = NSDate(timeIntervalSinceNow: -NSProcessInfo.processInfo().systemUptime)
    

    And then you can get the real date for the Accelerometer event:

    let eventDate = NSDate(timeInterval: data.timestamp, sinceDate: bootTime)
    

    I see that you asked this 25 days ago, but i hope it still be useful for anyone.