问题
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