Dateformatter changes the year of my date

I am trying to display a date using dateformatter, but that will change the year of the date.

This is the method:

setLabelWithDate:(NSdate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateFormatter setTimeZone:gmt];    
    [dateFormatter setDateFormat:@"dd MMMM YYYY"];

    NSLog(@"Date : %@",date);
    NSLog(@"stringFromDate %@",[dateFormatter stringFromDate:date]);

    self.selectedDateLabel.text = [dateFormatter stringFromDate:date];
    [dateFormatter release];
}

And here is what is displayed in the console:

2012-05-04 13:08:50.442 MyAppli[3339:fb03] Date : 2012-12-30 00:00:00 +0000
2012-05-04 13:08:50.443 MyAppli[3339:fb03] stringFromDate 30 December 2013

Here I am m. DateFormatter adds myDate one year and I really don't know why. This case only happens for the last two dates of the year (December 30 and 31).

Thank you for your help.

Alexander

+5
source share
1 answer

Using

[dateFormatter setDateFormat:@"dd MMMM yyyy"]; // lowercase y

and you should probably check this and this .

+8
source

All Articles