0

我有一个 UIDatePicker。我选择凌晨 2:30,它通过我的日期时间为早上 6:30。我究竟做错了什么?谢谢

这是代码:

_datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, toolBar.frame.size.height, vcSize.width, 0)];
_datePicker.minimumDate = [NSDate date];
[_datePicker addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
_datePicker.minuteInterval = 15;
_datePicker.timeZone = [NSTimeZone localTimeZone];
_datePicker.calendar = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar];
4

2 回答 2

0

这可能是您 在 iOS 4 中遇到的关于时区 UIDatePicker 错误的问题

于 2012-09-06T05:54:09.393 回答
-1
you  can select the date in to datePicker:

NSDate *date =  self.datePicker.date;

并且您在 datepicker 中选择任何日期将显示标签:

    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(500, 160, 340, 300)];
    datePicker.datePickerMode = UIDatePickerModeDate;
    datePicker.hidden = NO;
    datePicker.date = [NSDate date];
    [datePicker addTarget:self
                   action:@selector(LabelChange:)
         forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:datePicker];

-(void)LabelChange:(id)sender
{

 NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateStyle = NSDateFormatterMediumStyle;

    datelabel.text = [NSString stringWithFormat:@"%@",
                  [df stringFromDate:datePicker.date]];


if ([datePicker.date isEqualToDate:datePicker.date]) 
{
    NSLog(@"datePicker......");
}

[df release];

}
于 2012-09-06T06:10:38.037 回答