我有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;
}
最佳答案
我得到了我需要的如下:
-(NSString *)formattedDateString {
返回[self formattedStringUsingFormat:@“ yyyy-MM-dd HH:mm:ss ZZZ”];
}
关于ios - 为什么我会从“2010-12-31 15:00:00 +000”获得“2010-01-01 00:00:00 +900”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4570188/