你如何从UIDatepicker获得数值?

时间:2011-08-04 15:21:59

标签: iphone c++ xcode uidatepicker

我正在开发一个应用程序,它涉及从日期选择器中获取值并从实际iphone上显示的日期中减去它。我该怎么做?我到处寻找答案!

谢谢Rafee

1 个答案:

答案 0 :(得分:1)

您应该将datePickerValueChanged实现为选择器,并按此实现。

- (void)datePickerValueChanged:(UIDatePicker*) date_Picker{


NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
NSString *dateFromPicker = [NSString stringWithFormat:@"%@",[df stringFromDate:date_Picker.date]];

    // calculating time difference now

    NSDate *timeRightNow = [NSDate date];
    NSTimeInterval diff = [timeRightNow timeIntervalSinceDate:date_Picker.date];

    // The difference should always be in seconds. Here, 3628800 represents 6 weeks.

    if (diff > 3628800){

      // Do something if the entered date is six weeks from the iPhone date.

   }


 }