PhoneGap iOS LocalNotifications Daylight Savings

☆樱花仙子☆ 提交于 2019-12-06 09:20:19

Ah there seems to be a bit of a strange issue when notifications are set.

Example 1: When I do something like this, where duedate is a value of 2013-04-08T21:30

var d = new Date(duedate).getTime();
d = new Date(d);

plugins.localNotification.add({
date: d,
...

The notification is logged as being set for 21:30, like so:

Notification Set: 2013-04-08 21:30:00 +0000

Example 2: if I set the duedate like this: (where the time now is 21:30)

var d = new Date().getTime();

The notification is logged as being set for 20:30, like so:

Notification Set: 2013-04-08 20:30:00 +0000

However in the second example the notification fires at 21:30, due to day light savings.

Solution (of sorts)

I'm going to have to add or subtract the difference in time between now and when I want the notification to fire, rather than set the date specifically.

Drew Dahlman

This is rather interesting. One of the biggest things I deal with while creating the plugin was the weird way that JS and OBJ-C interpret time. According to docs you can use the systemTimeZone but that is again set by the system which is what the plugin is relying on. That is the time that the user has set and the phone is using.

Even thought it defaults to the +000GMT it still accounts for this in the system time and makes the adjustments for +0500 or what ever zone you're in.

UILocalNotification not using the correct timezone

NSTimeZone: what is the difference between localTimeZone and systemTimeZone?

Both deal with this - the plugin by default is using the system time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!