简体   繁体   English

如何将W3C日期XML转换为NSDate iOS

[英]How convert W3C Date XML to NSDate iOS

Problem: I parse XML contain date 2011-03-28T22:13:06.000+09:00 I using NSDateFormatter with parten YYYY-MM-DDThh:mm:ss.sTZD in http://www.w3.org/TR/NOTE-datetime But it not working 问题:我解析XML包含日期2011-03-28T22:13:06.000 + 09:00我使用NSDateFormatter与parten YYYY-MM-DDTHH:MM:ss.sTZD在http://www.w3.org/TR/NOTE -datetime但它不起作用

How convert this string to Date in IOS? 如何在IOS中将此字符串转换为Date?

Thank you 谢谢

NSDateFormatter* formatter = [NSDateFormatter new];
NSLocale* en_US_POSIX = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:en_US_POSIX];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
NSDate* date = [formatter dateFromString:dateString];

The two locale lines are usually omitted but are necessary to cover an odd configuration case on iPhone. 通常会省略两条语言环境行,但对于覆盖iPhone上的奇怪配置情况是必需的。 Add appropriate releases if not using ARC. 如果不使用ARC,则添加适当的发行版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM