trying to use a uidatepicker. have a method that fires when the value of the datepicker changes. it passes the date value, but when i try and take that date, my days portion is acting goofy. it returns the number of days since the beginning of the year, not the actual month day. so say February 3rd, instead of 3, i get 34.
-(IBAction)datePickerValueChanged: (id)sender;
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-DD"];
self.date = [dateFormatter stringFromDate:[sender date]];
NSLog(@"date: %@", [dateFormatter stringFromDate:[sender date]]);
[dateFormatter release];
}
for april 12th, i get:
2011-10-27 14:22:41.939 Satshot[12789:40b] date02: 2011-04-102
i’m guessing my dateformatter is causing it, but i don’t understand why.
You are using the wrong format specifier. You need
"yyyy-MM-dd"http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns
Update, YYYY and DD are both wrong. Thanks @jrturton.