【问题标题】:timezone to date in beirut lebanon黎巴嫩贝鲁特迄今为止的时区
【发布时间】:2014-03-20 07:26:37
【问题描述】:

我有一个来自 ios 日期选择器的日期,我得到了日期和时间,并将其转换为字符串并保存在 localStorage 中。然后,我得到这个字符串日期并将其转换为 NSDate 并在我的通知中使用它。但我的问题是通知没有运行,因为转换后日期发生了变化。

选择器的时间和日期是dateFromPicker=Thursday-20-March-2014 09:21 AM

picker 4 小时前的时间和日期是 :StringDateBefore4hours=Thursday-20-March-2014 05:21 AM

转换为NSDate后4小时前的字符串时间为DateBefore4hours=2014-03-20 00:21:00 +0000

时间改变了,我的通知没有在选择的时间运行,请帮帮我。

【问题讨论】:

  • UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.alertBody = @"考试当天本地应用通知"; [通知 setFireDate:dateBfore4hours]; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  • 请告诉我们你是怎么做到的:i get the date and the time and i convert this to string and saved in localStorage, then a get this string date and convert this to NSDate
  • 我的意思是我将字符串日期转换为 NSDate 形式并在通知中使用它,但转换时时间改变了

标签: ios date notifications uilocalnotification localnotification


【解决方案1】:

That is code for getting date from picker and assigning to notification

NSDate *date=[self.DatePicker date];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.alertBody = self.TextField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber=[[UIApplication       sharedApplication]applicationIconBadgeNumber]+1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2020-07-02
    • 2018-08-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多