开发者

NSDateFormat buggy?

I have the following code:

NSDateFormatter * df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd开发者_如何转开发 hh:mm:ss"];
date1 = [df dateFromString:@"2010-08-12 08:00:00"];

works as a charm, however when it is above 12:00:00, such as 23:00:00 the returned NSDate is null. Am I being stupid?


use HH instead of hh to represent 24-hr format

[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];


You need to use a capital HH for military time, hh is for AM/PM


Change your hh to HH.

I assume the format string is not correct for your format.

Looking at the strings that can be supplied to setDateFormat, the Apple doc points to spec http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns.

hour
h   1..2    11  Hour [1-12].
H   1..2    13  Hour [0-23].
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜