How can I get only the开发者_Go百科 date from a DatePicker component on iPhone? (better with a specific format).
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];
datePicker.datePickerMode = UIDatePickerModeDate;
From the documentation:
The exact order of these items depends on the locale setting.
In your question you mention you want it from DatePicker component!
Anyways.. see NSDateFormatter
精彩评论