我正在使用 NSDateFormatter 和 datefromString 是一整年
NSString *date = [[command substringWithRange:NSMakeRange(pos.location + 3, command.length - pos.location - 9)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@" date [%@] " , date );
NSLog(@" lastAccess [%@] " , lastAccess );
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss Z"];
[dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *filedate = [dateFormat dateFromString:date];
NSLog(@"1 %@ %f " , filedate , [filedate timeIntervalSince1970]);
NSLog(@"2 %@ %f " , lastAccess , [lastAccess timeIntervalSince1970]);
NSLog(@"3 %@ " , date);
产生以下输出
date [2012-11-18 19:00:23 +0000]
lastAccess [2012-11-18 19:00:21 +0000]
1 2011-11-18 19:00:23 +0000 1321642823.000000
2 2012-11-18 19:00:21 +0000 1353265221.929860
3 2012-11-18 19:00:23 +0000
日期有 2012 年,再次用 3 确认)
但请查看 1)它有 2011 年 1)文件日期 datefromstring of date
有任何想法吗 ?
提前致谢