2

如果我使用以下方法在 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]
}
4

1 回答 1

2

你试过NSFileManager吗?

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:@"data.json" error:nil];

NSDate *date = [attributes fileModificationDate];
于 2013-11-09T00:43:19.463 回答