I want to parse a date from a given string. The format of the string is always like this: “YYMMDD” e.g. 110831 which would be the year 2011, month august and day 31. So for testing purpose I wrote this small piece of code:
NSString* strDate = [NSString stringWithFormat:@"110803"];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYMMDD"];
NSDate* date = [dateFormatter dateFromString:strDate];
NSLog(@"date = %@", date );
The problem: The output of NSLog is always 2011-01-02 23:00:00 +0000 or 2011-01-29 23:00:00 +0000 for “110829” the same output is delivered for “110630”. So I know day one starts with a zero but the month is not recognized correctly. Therefore I’m asking myself what am I doing wrong here?
See
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1
and
http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns