我想在 Windows 环境中使用 node.js 每 1 小时运行一次打印语句。我使用包 node-schedule。
但是当我尝试运行它时,输出并不像预期的那样。我认为我的日程安排格式有误。
所以我尝试了下面的代码:
var schedule = require('node-schedule');
var j = schedule.scheduleJob('*/1 * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
最佳答案
var schedule = require('node-schedule');
var j = schedule.scheduleJob('* 1 * * *', function(){ // this for one hour
console.log('The answer to life, the universe, and everything!');
});
The cron format consists of:
* * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ | │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) │ │ │ │ └───── month (1 - 12) │ │ │ └────────── day of month (1 - 31) │ │ └─────────────── hour (0 - 23) │ └──────────────────── minute (0 - 59) └───────────────────────── second (0 - 59, OPTIONAL)
关于node.js - 使用nodejs每1小时调度一次文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34735908/