views:

81

answers:

2

February, 26 2010 21:34:00

Based on all the documentation I can find, MMMM, d yyyy H:m:s should be correct - but my NSDate dateFromString is returning null.

A: 

What region is the phone set to? If it's not en_US, you'll have to set the date formatter to it using setLocale.

DyingCactus
[inputFormatter setLocale:[NSLocale systemLocale]]; and I believe that is en_US
E-Madd
A: 

I once had lots of trouble with exactly this kind of problem until I explicitly set the formatter to en_US locale. systemLocale is NOT good because it may be something other than en_US, affecting e.g month/weekday names etc. This is a piece of working code:

NSDateFormatter *fmt = [[[NSDateFormatter alloc] init] autorelease];    
[fmt setDateFormat:@"eee MMM dd HH:mm:ss Z yyyy"];
[fmt setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
NSDate *formattedDate = [fmt dateFromString:someStringContainingDate];
Jaanus