BobC
BobC

Reputation: 655

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];
[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.

Upvotes: 1

Views: 331

Answers (1)

awurzer
awurzer

Reputation: 36

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/

Upvotes: 2

Related Questions