Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePicker iPhone get only date

How can I get only the date from a DatePicker component on iPhone? (better with a specific format).

like image 233
Andrea Mattiuz Avatar asked Jul 28 '10 10:07

Andrea Mattiuz


2 Answers

I believe that your answer can be found in this previous question: Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

Just take the date you get back from the datePicker and get just the day using NSDateFormatter:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSString *theDate = [dateFormat stringFromDate:pickerDate];
[dateFormat release];
like image 103
bjtitus Avatar answered Sep 28 '22 00:09

bjtitus


datePicker.datePickerMode = UIDatePickerModeDate;

From the documentation:

The exact order of these items depends on the locale setting.

like image 29
Ole Begemann Avatar answered Sep 27 '22 23:09

Ole Begemann