使用timeIntervalSince1970转换时,如何将fileCreationDate的精度提高到6位小数?

时间:2013-07-05 11:24:13

标签: ios nsdate nslog nstimeinterval nsdocumentdirectory

转换为fileCreationDate时,如何将NSDocumentsDirectory中存储的文件的NSTimeInverval精确到小数点后6位?

一些代码:

//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);

此代码的示例输出为:

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

是否可能或者是NSDocuments中的存储限制?

1 个答案:

答案 0 :(得分:0)

这是操作系统级别的限制。 HFS+,iOS使用的文件系统,日期分辨率为1秒 - 这就是为什么所有文件时间戳都是整秒。不支持次秒精度。遗憾!