views:

47

answers:

1
NSString *dateStr = @"2010-06-07 19:30:18";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-DD hh:mm:ss"]; 
NSDate *date = [dateFormatter dateFromString:dateStr];

date is always nil. But the date format seems to be correct. What's wrong?

Edit: Seems to work with @"yyyy-MM-DD HH:mm:ss"

+3  A: 

Just a guess - try using HH instead of hh. On many systems, hh means 12 hour hour of day (01-12) whereas HH means 24 hour (00-23):

[dateFormatter setDateFormat:@"yyyy-MM-DD HH:mm:ss"];
Jon Skeet