https://www.npmjs.org/package/node-schedule
代码:
var http = require('http');
var port = process.env.PORT || 8080;
var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [0, 6];
rule.hour = 12;
rule.minute = 25;
var j = schedule.scheduleJob(rule, function(){
console.log('Yup!');
});
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
}).listen(port);
console.log("Node server listening on port " + port);
我从命令行启动了服务器,所以这应该打印“Yup!”在12.25的控制台,但它没有。可能是什么问题?
答案 0 :(得分:0)
使用此:
rule.dayOfWeek = [0, new schedule.Range(1, 6)];
而不是:
rule.dayOfWeek = [0, 6]; this one