4

I actually retrieve string date with the format "Sun, 08 Jan 2012 13:57:38 +0000" For that I use the dateFormat "EEE, dd MMM yyyy HH:mm:ss ZZZ" But it doesn't work...

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];
NSLog(@"%@",[dict objectForKey:@"created_at"]);
NSDate *dateFromString = [dateFormatter dateFromString:[dict objectForKey:@"created_at"]];
NSLog(@"%@",dateFromString);

For the first NSLog it displays me "Sun, 08 Jan 2012 13:57:38 +0000" But the second is (null)

I don't understand where I am wrong. Please tell me if you see something wrong.

Thanks

kschaeffler
  • 4,083
  • 7
  • 33
  • 41

1 Answers1

3

Your date string is in English. If your device or simulator locale is set to another language, that could be the problem. If so, you need to set the locale for the NSDateFormatter to English.

Like this:

[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
Jim Rhodes
  • 5,021
  • 4
  • 25
  • 38