UIDatePicker错误的时间

时间:2012-09-06 05:33:59

标签: objective-c ios cocoa-touch uidatepicker

我有一个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];

2 个答案:

答案 0 :(得分:0)

这可能是您所面临的时区问题 UIDatePicker bug in iOS 4

答案 1 :(得分:-1)

you  can select the date in to datePicker:

NSDate *date =  self.datePicker.date;

并选择日期选择器中的任何日期将显示标签:

    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];

}