我有一个字符串在UTC,我想转换为NSDate。不知何故即时得到30分钟错误NSDateFormatter错误:不正确的字符串到日期转换
该字符串是 2012-04-10T00:00:00 + 05:30
转换后的日期是 2012-04-09 19点00分00秒+ 0000
地方,因为它本来应该 2012-04-09 18:30:00 +0000
即时通讯使用此功能将字符串转换为日期
- (NSDate *)parseRFC3339Date{
NSDateFormatter *rfc3339TimestampFormatterWithTimeZone = [[NSDateFormatter alloc] init];
[rfc3339TimestampFormatterWithTimeZone setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *theDate = nil;
NSError *error = nil;
if (![rfc3339TimestampFormatterWithTimeZone getObjectValue:&theDate forString:self range:nil error:&error]) {
NSLog(@"Date '%@' could not be parsed: %@", self, error);
}
[rfc3339TimestampFormatterWithTimeZone release];
return theDate;
}