views:

61

answers:

2

Why is lDateFormatted nil on iPhone simulator 3.1.2 after executing this piece of code?

NSString *lDateString = @"Wed, 17 Feb 2010 16:02:01";
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy hh:mm:ss"];
NSDate *lDateFormatted = [dateFormatter dateFromString: lDateString ];

Any ideas appreciated, Thanks

+1  A: 

You probably want to be using HH for hours, that's 0-23 / military style Also, you may need to put single ticks around your comma like ','

Reference: the UTS doc and date formatting guide.

slf
In this case the ticks didn't seem to be necessary, but I put them in anyway. Thanks!
Kristof
A: 

The DateFormatter format is correct, but you've probably set the wrong locale. Try this one (working sample code of one of my projects):

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSLocale *enUS = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter setLocale:enUS];
[enUS release];
[formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss"];
...
[formatter release]

alex