xcode 此时如何从 datePicker 和 run 方法获取时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6995466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:41:41  来源:igfitidea点击:

how to get time from datePicker and run method in this time ?

iphoneobjective-ciosxcodedatepicker

提问by Amir Foghel

i want to get time from datePicker into NSDate object, and then to run a method every day in this time. for example: the user put in the datePicker the tome 08:00 and every day in 08:00 the application will run some method.

我想从 datePicker 获取时间到 NSDate 对象中,然后在这个时间每天运行一个方法。例如:用户在 datePicker 中 08:00 和每天的 08:00 将运行一些方法。

Thank you very much, Amir Foghel

非常感谢,阿米尔福赫尔

回答by KingofBliss

To get the time from datepicker use ,

要从 datepicker 使用获取时间,

NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm"]; //24hr time format
NSString *dateString = [outputFormatter stringFromDate:self.myDatePicker.date];
[outputFormatter release];

To do a functionality at particular time daily use UILocalNotification.

要每天在特定时间执行功能,请使用UILocalNotification

Set the repeatInterval as NSDayCalendarUnit.

将repeatInterval 设置为NSDayCalendarUnit。

And in the delegate to handling the UILocalNotification code your method.

并在委托中处理 UILocalNotification 代码您的方法。

NOTE:This method will be execute only when the user accepts the Local notification.

注意:只有当用户接受本地通知时,才会执行此方法。