views:

102

answers:

1

Hello guys, 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.

+2  A: 

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/

awurzer
omg.... Thanks!
BobC
Actually, the better reference is the Unicode standard: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
nall
@nall great stuff, thanks.Apple should have also included this in its documentation.
Biranchi