2017-11-17 12 views
-1

ノードJsでスケジューラを作成してサービスを呼び出し、特定の要求に電子メールを送信したいと考えています。予定日ノードjs

リリース日= 20/03/2017

スケジューラは、1ヶ月2ヶ月で、15日のリリース日前。 私は私よりよい解決策を提供してください 機能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スケジュールは=( 'ノードスケジュール')を必要とする以下、これを試みました。 VARジョブ= schedule.scheduleJob({時間:10分:0}、関数(){ checkRelease(); `この関数は時間の差を確認し

  1. サービスを呼び出すリスト項目

    「 });

+0

あなたがこれまでに試してみましたか? –

+0

スケジューラが毎日電話をかけているので、現在の日付を確認して違いを見つける必要があります。 –

+0

function checkRelease(){ \t var date = '2017-11-18T07:05:32.950Z'; \t var release = new Date(date); \t console.log(リリース); \t var current = new Date(); \t console.log(現在); \t var timeDifference = Math.abs(release.getTime() - current.getTime()); \t console.log(timeDifference); \t var differentDays = Math.ceil(timeDifference /(1000 * 3600 * 24)); \t console.log(differentDays); \t if(differentDays === 1){ \t \t console.log( "1 day"); \t}そうであれば(differentDays === 28 || differentDays === 29 || differentDays === 30 || differentDays === 31){ \t \tはconsole.log( "1月") \t} –

答えて

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` 

});