本地通知安排为3个月,从现在开始使用离子6个月 [英] Local notifications schedule for 3 months, 6 moths from now using ionic
问题描述
我正在使用ionic和cordova开发提醒应用程序。
I'm developing reminder app using ionic and cordova.
对于本地通知,我使用过科尔多瓦 - 插件本地的通知。
默认情况下,此插件仅包含日,月,年或周间隔。我想自定义计划时间,例如指定时间,3个月,6个月,2年或5年。
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.
谢谢!
推荐答案
如项目维基,您可以使用此代码延迟本地通知:
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
});
我建议您使用专用的js库来操作日期,例如 moment.js 。这将帮助您避免许多头痛,代码将更加清晰。
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.
这篇关于本地通知安排为3个月,从现在开始使用离子6个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!