I have the following code:
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
/*2010-11-02 20:31:39*/
[df setDateFormat:@"YYYY-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With