有的時候須要根據業務須要,晚上凌晨之後執行某些操做的時候,這個可能會有所幫助,我最近正在研究這個,歡迎共同探討。node
github地址:https://github.com/mattpat/node-schedulegit
安裝github
npm install node-schedule
1.肯定時間,例如:2012年11月21日,5:30npm
var schedule = require('node-schedule'); var date = new Date(2012, 11, 21, 5, 30, 0); var j = schedule.scheduleJob(date, function(){ console.log('The world is going to end today.'); }); 取消預設計劃 j.cancel();
2.每小時的固定分鐘,例如:每一個小時的42分鐘post
var schedule = require('node-schedule'); var rule = new schedule.RecurrenceRule(); rule.minute = 42; var j = schedule.scheduleJob(rule, function(){ console.log('The answer to life, the universe, and everything!'); });
3.一個星期中的某些天的某個時刻,例如:每週四,週五,週六,周天的17點ui
var rule = new schedule.RecurrenceRule(); rule.dayOfWeek = [0, new schedule.Range(4, 6)]; rule.hour = 17; rule.minute = 0; var j = schedule.scheduleJob(rule, function(){ console.log('Today is recognized by Rebecca Black!'); });