views:

84

answers:

1

I am trying to create a formatter that will convert the date format shown to an NSDate object:

NSString *dateStr = @"2010-06-21T19:00:00-05:00";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
NSDate *date = [dateFormat dateFromString:dateStr];  

The issue is the timezone -05:00, which is not parsed properly with the format above. Any suggestions?

A: 

Honestly, you'll just have to change the source data (removing the colon) before running it through the formatter. Your original date string is non-standard and none of the time zone format strings will work properly on it.

You can see the valid inputs on unicode.org.

ZZZ e.g. "-0500"

ZZZZ e.g. "GMT-05:00"

Nothing for "-05:00"

chrissr
After trying any number of approaches, that is what I settled on as well. Thanks
John
btw, here is a related objective-c library: http://github.com/square/iso8601parser
John