im using xcode 4.5(4G182) with iOS 6. NSDateFormatter show wrong year in iOS 6, how to solve?
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"YYYY-MM-dd"];
NSString *str = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@ == %@",str,[[dateFormatter dateFromString:str] description]);
it print out "2012-09-14 == 2011-09-13 16:00:00 +0000"
YYYY
is not the same asyyyy
.According to this page which the IOS Date format page references;
The operative sentence being the last one. Use
yyyy
instead.Further details on how and why the year values may deviate when using
YYYY
:From https://en.wikipedia.org/wiki/ISO_8601#Week_dates (bold styling added)