开发者

NSDateFormatter confusion

开发者 https://www.devze.com 2022-12-08 08:54 出处:网络
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:

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

精彩评论

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