如何从 UIDatepicker 获取数值?

发布于 2024-11-27 23:03:28 字数 84 浏览 0 评论 0原文

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

谢谢拉菲

i am developing an app that involves getting a value from a datepicker and subtracting it from the date displayed on the actual iphone. how will i do this? i have looked everywhere for an answer!

thanks Rafee

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-12-04 23:03:28

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

   }


 }  

You should implement datePickerValueChanged as the selector, and implement like this.

- (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.

   }


 }  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文