gpt4 book ai didi

iphone - 如何从 UIDatepicker 获取数值?

转载 作者:行者123 更新时间:2023-11-28 08:18:12 25 4
gpt4 key购买 nike

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

谢谢拉菲

最佳答案

您应该将 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.

}


}

关于iphone - 如何从 UIDatepicker 获取数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6944083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com