Converting ex. 2010-09-11T00:00:00+01:00 format to NSDate

不想你离开。 提交于 2019-12-03 00:08:40

TZD isn't a defined formatter per the unicode spec. The document you've linked to elsewhere was a suggestion someone made to W3C, for discussion only. The unicode standard followed by Apple is a finished standard, from a different body.

The closest thing to what you want would be ZZZ (ie, @"YYYY-MM-dd'T'HH:mm:ssZZZ"), but that doesn't have a colon in the middle. So you'd need to use the string:

2010-09-11T00:00:00+0100

Rather than the one you currently have that ends in +01:00.

E.g. the following:

NSString * dateString = @"2010-09-11T00:00:00+0100";
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssZZZ"];
NSDate  *date = [formatter dateFromString:dateString];
NSLog(@"%@", date);

Logs a valid date object, of 2010-09-10 23:00:00 GMT.

Tip: try using your formatter to convert from an NSDate object to a string, then see what you get. It's often easier to debug in that direction than the other.

Have you read this?

http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns

That TZD at the end of your format string looks a bit dodgy.

I solved this issue using this code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!