How can I get the fileCreationDate to an accuracy of 6 decimal places when converted using timeIntervalSince1970?

StackOverflow https://stackoverflow.com/questions/17487756

Question

How can I get the fileCreationDate for a file stored in the NSDocumentsDirectory to an accuracy of 6 decimal places when converted to an NSTimeInverval?

Some code:

//Not accurate enough:
NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:myPhotoPath error:nil]; 
NSDate *creationDateOfPhoto = [fileAttribs fileCreationDate];
NSTimeInterval creationDateAsTimeInterval = [creationDateOfPhoto timeIntervalSince1970];
NSLog(@"Creation Date of Photo As Time Interval Since 1970: %f", creationDateAsTimeInterval);

//With the desired accuracy:
NSDate* now = [NSDate date];
NSTimeInterval nowStampAsTimeInterval = [now timeIntervalSince1970];
NSLog(@"Now As Time Interval Since 1970: %f", nowStampAsTimeInterval);

A sample output from this code is:

Creation Date of Photo As Time Interval Since 1970: 1373022866.000000
Now As Time Interval Since 1970:                    1373022884.294028

Is it possible or is it a limitation of storage in NSDocuments?

Was it helpful?

Solution

It's a OS level limitation. HFS+, the file system which is used by iOS, has a date resolution of one second - this is why all your file timestamps are whole seconds. Sub second precision isn't supported. Sorry!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top