开发者

NSDateFormatter confusion

I'm trying to use dateFromString method from NSDateFormatter but it somehow doesn't work for me. I made a test case to show my problem:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];开发者_JAVA技巧
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:MM"];

NSString *kkk = @"Thu, 15 Oct 2009 10:00";
NSString *test = [dateFormatter stringFromDate:[NSDate date]];

NSLog(test);
-- result is: Thu, 15 Oct 2009 14:10

NSDate *d = [dateFormatter dateFromString:kkk];
--result is nil

I'm on iPhone.


I think the given format especially HH:MM is the problem, since uppercase MM means month instead of minutes. For minutes use lowercase mm - found in http://www.stepcase.com/blog/2008/12/02/format-string-for-the-iphone-nsdateformatter/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜