开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜