views:

137

answers:

2

I use this code to process a date string coming in from a json feed:

NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle: NSDateFormatterLongStyle];
[formatter setFormatterBehavior: NSDateFormatterBehavior10_4];
[formatter setDateFormat: @"EEE, dd MMM yyyy HH:mm:ss +0000"];

so if I call

NSDate *date = [formatter dateFromString: @"Tue, 08 Sep 2009 19:21:27 +0000"];

I get back a usable date if my region format is United States or United Kingdoms, but if I set it to Germany it returns nil. I understand there are some differences in behaviors across different locales, but if I define a format shouldn't that correct for any inconsistencies?

+2  A: 

Names like "Tue" and "Sep" are English. Other languages use different names.

If you want to be able to parse English dates independent of the device's region settings, set your DateFormatter's locale to en_US using the -setLocale: method.

Darren
A: 

Thanks fixed it up with: [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]];