我从日期选择器中选择日期,但它只显示运行时的时间。
我只想要日期,而不是时间,但它只显示时间而不是日期。我已经设置了日期格式。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
DatePicker.datePickerMode = UIDatePickerModeTime;
NSString *formatedDate=[[NSString alloc]init];
formatedDate = [dateFormatter stringFromDate:self.DatePicker.date];
self.SelectedDate.text =formatedDate;
[DatePicker setMinimumDate: [NSDate date]];
_goDateForcustmoeDetail=formatedDate;
isTouchedFirst=NO;
答案 0 :(得分:2)
尝试更改
DatePicker.datePickerMode = UIDatePickerModeTime;
到
DatePicker.datePickerMode = UIDatePickerModeDate;
只有四种模式可用:
- UIDatePickerModeTime,
- UIDatePickerModeDate,
- UIDatePickerModeDateAndTime,
- UIDatePickerModeCountDownTimer
答案 1 :(得分:1)
将datePicker模式设置为UIDatePickerModeDate
..简单!!
DatePicker.datePickerMode = UIDatePickerModeDate;
@ 只有四种模式可用:
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
答案 2 :(得分:1)
只需在视图控制器中拖放UIDatePicker即可。 添加此代码,您将只获得日期
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
_DatePicker.datePickerMode = UIDatePickerModeDate;
NSString *formatedDate=[[NSString alloc]init];
formatedDate = [dateFormatter stringFromDate:self.DatePicker.date];
[_DatePicker setMinimumDate: [NSDate date]];