0

当转换为 时,如何获得fileCreationDate存储在NSDocumentsDirectory6 位精度的文件NSTimeInverval

一些代码:

//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 中的存储限制?

4

1 回答 1

0

这是操作系统级别的限制。iOS 使用的文件系统HFS+的日期分辨率为一秒 - 这就是为什么所有文件时间戳都是整秒的原因。不支持亚秒精度。对不起!

于 2013-07-05T12:01:16.103 回答