Question

I am using UIDatePicker to select the date. I have selected only DateMode in this. Sometimes, its behaving differently

If i select December 17,2014 in calander. Its giving me the string as selected date is 2014-12-351 and it should be 2014-12-17 instead.

code below is used to get the string from UIDatePicker.

  NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"YYYY-MM-DD"];
  NSString *selectedDate = [NSString stringWithFormat:@"%@",
                              [df stringFromDate:datepicker.date]];

Please help me in this

Was it helpful?

Solution

From @Hot Licks comment,

Use correct date format as yyyy-MM-dd. For further reference read Date Format Patterns

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top