我想在Node Js中创建调度程序来调用服务并向特定请求发送电子邮件。
发布日期= 2017年3月20日
计划程序是2个月1个月和发布日期前15天。 我试过这个,请给我更好的解决方案 function checkRelease(){
var date = '2017-11-18T07:05:32.950Z';
var release = new Date(date);
console.log(release);
var current = new Date();
console.log(current);
var timeDifference = Math.abs(release.getTime() - current.getTime());
console.log(timeDifference);
var differentDays = Math.ceil(timeDifference / (1000 * 3600 * 24));
console.log(differentDays);
if(differentDays === 1){
console.log("1 day");
} else if(differentDays === 15){
console.log("15 day");
} else if(differentDays === 28 || differentDays === 29 || differentDays === 30 || differentDays === 31){
console.log("1 month");
} else if(differentDays === 58 || differentDays === 59 || differentDays === 60 || differentDays === 61 || differentDays === 62){
console.log("2 month");
}
}
var schedule = require(' node-schedule'); var job = schedule.scheduleJob({hour:10,minute:0},function(){ checkRelease();`此函数检查时间差异和呼叫服务
列出项目
` });
答案 0 :(得分:0)
relDate ="2017-11-21T20:58:00.000Z";
var current = new Date();
console.log(current);
var timeDifference = Math.abs(relDate.getTime() - current.getTime());
var differentDays = Math.ceil(timeDifference / (1000 * 3600 *24));
console.log(differentDays);
if(differentDays === 1){
console.log("1 day");
} else if(differentDays === 15){
console.log("15 day");
} else if(differentDays === 28 || differentDays === 29 || differentDays ===
30 || differentDays === 31){
console.log("1 month");
} else if(differentDays === 58 || differentDays === 59 || differentDays ===
60 || differentDays === 61 || differentDays === 62){
console.log("2 month");
}
**output**
1 day
i call this function inside scheduler in app.js
//---Sechduler for release and roration date
var job = schedule.scheduleJob({hour: 18, minute:54}, function(){
checkRelease();`call function`
});