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

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

문제

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?

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top