Jonovono
Jonovono

Reputation: 2085

Converting this date string to NSDate

So I am trying to convert something like: "Mon Dec 02 2013 01:45:08 GMT-0600 (CST)"

This works great if I don't have the ending on it (GMT-0600 (CST)):

NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"EEE MMM dd yyyy HH:mm:ss z"];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"EN"]];
NSDate *myDate=[dateFormatter dateFromString:@"Mon Dec 02 2013 01:45:08 GMT-0600 (CST)"];
NSLog(@"--> %@",myDate);

But since I do, it does not seem to work.

Upvotes: 0

Views: 60

Answers (1)

Sviatoslav Yakymiv
Sviatoslav Yakymiv

Reputation: 7935

Try to use following date formatter. It works for me:@"EEE MMM dd yyyy HH:mm:ss 'GMT'zzzz (zzz)"

Upvotes: 1

Related Questions