I can see a really strange date conversion in my app. This is the code:
theDateString = [theDateFormatter stringFromDate:date];
If date is 2007-12-31 00:00:00 +0100
theDateString is 2008
but if date is 2004-12-31 00:00:00 +0100
theDateString is 2004.
The method is - (NSString *)stringFromDate:(NSDate *)date in NSDateFormatter and it is a mac app.
The NSDateFormatter format is: [theDateFormatter setDateFormat:@"Y"];
Why ?
Thanks
You should use
@"y"instead of@"Y", because the capital “Y” specifies the year according to the “week of year”. The 52nd week of 2007 ends in 2008, that’s why it returns 2008 instead of 2007.Update:
See: http://waracle.net/mobile/iphone-nsdateformatter-date-formatting-table/