Why does NSDateFormatter return zero?

Why is lDateFormatted nil on the iPhone 3.1.2 simulator after this piece of code has been executed?

 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, thanks

+1
source share
2 answers

You probably want to use HH for a few hours, 0-23 / military style. In addition, you may need to set separate ticks around the comma, for example, ','

Reference: UTS document and date formatting guide .

+1
source

The DateFormatter format is correct, but you probably installed the wrong language. Try this (working example code from 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"];
...
[formatting release]

0
source

All Articles