What's the point of the format of the timestamp in NSEvent?

Hi

The NSTimeInterval returned from the NSEvent timestamp method gives the time in seconds since startup, but elsewhere in Cocoa the time (or NSDate) is returned with different references (now/1970/date etc.), bit not time since startup.

If I save the timestamp from an Event, and later on want to know the time elapsed between 'now' and that event, there seems no way to do this, or convert from startup time to any other time provide by NSDate.

Is there a way around this, and any idea why Apple would have chosen two seemingly incompatible formats in the first place?
(I realise I could, instead, save a 'now' time as soon as possible after the time of the event and compare against that, but it doesn't explain this quirk.)

Thanks

Steve

Mac Pro 2.8 8-core, Mac OS X (10.6.2), Developing desktop apps for Intel Mac

Posted on Apr 29, 2010 3:02 AM

Reply
4 replies

Apr 29, 2010 7:51 AM in response to Steve556

Hello Steve556

NSProcessInfo has the - (NSTimeInterval)systemUptime method that you can use to know the startUpTime at any given moment.

NSTimeInterval *eventTimeStamp; //assume this exists...
NSTimeInterval sinceStartUp = [[NSProcessInfo processInfo]systemUptime];//in seconds
NSDate *eventDate = [NSDate dateWithTimeIntervalSinceNow:-(sinceStartUp-eventTimeStamp)];

Maybe there is a better way...

Apr 29, 2010 8:11 AM in response to laurent demaret

laurent demaret wrote:
Hello Steve556

NSProcessInfo has the - (NSTimeInterval)systemUptime method that you can use to know the startUpTime at any given moment.

NSTimeInterval *eventTimeStamp; //assume this exists...
NSTimeInterval sinceStartUp = [[NSProcessInfo processInfo]systemUptime];//in seconds
NSDate *eventDate = [NSDate dateWithTimeIntervalSinceNow:-(sinceStartUp-eventTimeStamp)];

Maybe there is a better way...


Thanks Laurent, that's just what I needed.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

What's the point of the format of the timestamp in NSEvent?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.