如果我使用以下内容在ios应用程序中保存和检索数据,我怎样才能获得保存文件的时间?
-(void)saveJsonWithData:(NSData *)data{
NSString *jsonPath=[[NSSearchPathForDirectoriesInDomains(NSUserDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingFormat:@"/data.json"];
[data writeToFile:jsonPath atomically:YES];
}
-(NSData *)getSavedJsonData{
NSString *jsonPath=[[NSSearchPathForDirectoriesInDomains(NSUserDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingFormat:@"/data.json"];
return [NSData dataWithContentsOfFile:jsonPath]
}
答案 0 :(得分:2)
您是否尝试过NSFileManager
?
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:@"data.json" error:nil];
NSDate *date = [attributes fileModificationDate];