Hello I'm using the following NSFileManager method in an iPad application:
- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error
to get file attributes, then use the key NSFileModificationDate to get the latest file modification date/time. However, the date/time that it 开发者_StackOverflow社区is returning me is 5 hours ahead of the date that I actually save the file which is what I see inside my "Finder" when viewing properties of the file.
I know a workaround/hack would be to knock 5 hours of the time I get back but I'd like to know why this is happening. Anybody know? Thanks.
Remember file timestamps are always in UTC, and the Finder compensates for whatever timezone you're currently in when displaying, so you have to do the same.
Is this on-device or in the simulator? I'm guessing the latter since you refer to Finder in your question. In Simulator, the NSDate I get from the sample below doesn't give me a time zone. On-device behavior may be different; try it.
NSError * err;
NSFileManager * myManager = [NSFileManager defaultManager];
NSString * myPath = [[NSBundle mainBundle] bundlePath];
NSDictionary * myDict = [myManager attributesOfItemAtPath:myPath error:&err];
NSDate * myDate = [myDict objectForKey:@"NSFileModificationDate"];
NSLog(@"%@", myDate);
2011-01-26 21:32:29.985 scraptime2[11488:207] 2011-01-27 03:32:27 +0000
(I would post a comment but I don't have enough rep yet)
精彩评论