我想在 UIDatePicker 中只显示时间,minimumTime +12 小时。下面是我的代码:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"startTimeLabel %@", startTimeLabel);
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm a"];
NSDate *minimumTime = [formatter dateFromString:startTimeLabel];
NSLog(@"minimumTime Formatted %@", minimumTime);
UIDatePicker *pickerView = [[[UIDatePicker alloc] init] initWithFrame:CGRectMake(0, 40, 320, 216)];
pickerView.datePickerMode = UIDatePickerModeTime;
[pickerView setMinimumDate:minimumTime];
[pickerView setMinuteInterval:15];
[pickerView setTag: kDatePickerTag1];
//Add picker to action sheet
[actionSheet addSubview:pickerView];
NSArray *subviews = [actionSheet subviews];
}
这是日志:
2013-07-17 18:13:37.682 MeetingTime[12294:c07] startTimeLabel 6:15 PM
2013-07-17 18:13:37.683 MeetingTime[12294:c07] minimumTime Formatted 2000-01-01 20:15:00 +0000
Q1。为什么 startTimeLabel 显示为下午 6:15,但格式化后显示为 20:15:00+0000。不应该是 18:15 吗?我的格式错了吗?我不需要日期,我可以去掉它吗?
Q2。我希望选择器从 startTimeLabel 中获取最短时间并将其用作 minimumTime。是否可以在最短时间之前不显示任何时间?即如果 startTimeLabel 是下午 6:15,那么 UIPicker 中的唯一选项将是下午 6:30 + 12 小时?我怎样才能做到这一点?谢谢。