I try to display a date with a dateformatter but this one 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 this 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 m. The dateFormatter add myDate one year and I really don't know why. This case happens only for the 2 last dates of the year (30 and 31 december).
Thanks for your help.
Alexandre
Use
[dateFormatter setDateFormat:@"dd MMMM yyyy"]; // lowercase y
and you probably should check this and this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With