我有NSDate,如果我使用它会显示如下NSLog(@"%@", date.description);
2010-12-31 15:00:00 +0000
它会显示为好像我使用过NSLog(@"%@", [date descriptionWithLocale:[[NSLocale currentLocale] localeIdentifier]]);
2011 年 1 月 1 日星期六 12:00:00 AM 日本标准时间
但如果我使用它会显示如下NSLog(@"%@", [date formattedDateString]);
2010-01-01 00:00:00 +0900
我在哪里犯错?
- (NSString *)formattedDateString {
return [self formattedStringUsingFormat:@"YYYY-MM-dd HH:mm:ss ZZZ"];
}
- (NSString *)formattedStringUsingFormat:(NSString *)dateFormat {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:dateFormat];
NSString *ret = [formatter stringFromDate:self];
[formatter release];
return ret;
}