NSDateFormatter dateFromString returning nil
I have the following code:
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
/*2010-11-02 20:31:39*/
[df setDateFormat:@"YY开发者_如何学GoYY-MM-dd hh:mm:ss"];
NSDate* date = [df dateFromString:@"2010-11-02 20:31:39"];
date
is nil
.
Any idea why?
The hh
symbol is used for hours between 1 and 12. Use HH
for hours between 1 and 24. Also, YYYY
is used for the week-numbering year. You probably want yyyy
instead.
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
Check out Unicode Technical Standard #35 for details.
精彩评论