Local notifications schedule for 3 months, 6 moths from now using ionic

徘徊边缘 提交于 2019-12-11 08:35:50

问题


I'm developing reminder app using ionic and cordova.

For local notification I've used cordova-plugin-local-notifications. By default this plugin has only day, month, year or week interval. I want to customize the schedule time, specifying for example the time, 3 months, 6 months, 2 year or 5 year.

Please try to find out the solution for me.

Thank You!


回答1:


As reported in the project wiki, you can delay the local notification using this code:

var now             = new Date().getTime(),
_3_months_from_now = new Date(now + 3*30*24*60*60*1000),
_6_months_from_now = new Date(now + 2*_3_months_from_now),
_2_year_from_now = new Date(now + 4*_6_months_from_now),
_5_year_from_now = new Date(now + 10*_6_months_from_now),
_5_sec_from_now = new Date(now + 5*1000);

cordova.plugins.notification.local.schedule({
    text: "Delayed Notification",
    at: _3_months_from_now,
    led: "FF0000",
    sound: null
});

I suggest you to use a dedicated js library to manipulate dates, like moment.js. This will help you to avoid many headache and the code will be more clear.



来源:https://stackoverflow.com/questions/32349958/local-notifications-schedule-for-3-months-6-moths-from-now-using-ionic

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