可能重复:
Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?
Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset?目标C:将ISO 8601日期时间当地日期时间
我试图日期时间,这是ISO 8601格式转换int当地时间。 转换这样的:
2012-10-15T09:46:16+02:00
这样:
2012-10-15 11:46:16
我尝试下面的代码,但给空回
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
NSDate *dt = [dateFormatter dateFromString:@"2012-10-15T09:46:16+02:00"];
NSString *dateTime= [NSDateFormatter localizedStringFromDate:dt dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
NSLog(@"DATE FORMAT:%@", dateTime);
任何想法,我在做什么错?
请注意,虽然转换适当的时间应该计算 –
我厌倦了提供的links.none他们的作品。即使在我的例子中它也减去了2小时+2小时。如果时区为+04:30会发生什么? 投票表决不错,您可以再次投票,但请提供答案。 –
工作答案会很好 –