簡體   English   中英

使用timeIntervalSince1970轉換時,如何使fileCreationDate的精度達到小數點后6位?

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

我怎樣才能獲得fileCreationDate存儲在一個文件NSDocumentsDirectory時轉換為到小數點后6位的精度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中存儲的限制?

這是操作系統級別的限制。 HFS +是iOS使用的文件系統,其日期分辨率為一秒-這就是為什么所有文件時間戳都是整秒的原因。 不支持亞秒精度。 抱歉!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM