views:

248

answers:

2

I'm implementing iphone app with coredata functionality. I've an attribute in entity "NSDate" which stores the date and time when the record is added. I'm adding records at a faster rate. About 1 record per 25 milli seconds I want to store the date along with milli seconds so that I can retrieve the data in descending order. How can I do this?

The comments and answers are correct. But how can I retrieve the stored milli seconds data along with other records in descending format?

A: 

I think you can get the milliseconds of the day through: NSTimeInterval timeInterval = [date timeIntervalSince1970] and the NSTimeInterval is a long long, so you can save it into everywhere you want

vodkhang
A: 

An NSDate uses NSTimeInterval which has better than millisecond accuracy. If you want to skip NSDate you can use CFAbsoluteTimeGetCurrent() which returns the same value directly. Below that is gettimeofday() which returns a timeval with up to microsecond accuracy.

NSTimeInterval and CFTimeInterval are both type double, so just multiply by 1000 to get milliseconds.

NSDate calls CFAbsoluteTimeGetCurrent() calls gettimeofday() so they all have the same accuracy.

drawnonward