我有一個字符串在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;
}