Hopefully this is just a quick one and I’m missing something simple…
I’ve got an NSDateFormatter, which I’m using to convert the string 2011-11-10 into a Date object.
NSDateFormatter *fmtDate = [[NSDateFormatter alloc] init];
[fmtDate setDateFormat:@"YYYY-MM-DD"];
// input of 2011-11-10, output of 2011-01-10 00:00:00 +0000
[appointment setDate:[fmtDate dateFromString:
[tempAppointment objectForKey:@"date"]
]];
The return from the NSDateFormatter is stored in a managedObjectContext. My problem is that the dateFormatter is returning the date as 2011-01-10 00:00:00 +0000
Why is it reducing the month from Nobvember to January? It’s retaining the year and the day fine, but not the month.
Do I need to include the hours when I store the date? Or is it something to do with the format I set?
Your date format string is not correct using YYYY. Try yyyy-M-d or yyyy-MM-dd
Outputs:
See:
http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns