gpt4 book ai didi

javascript - 每日特定时间nodejs触发函数

转载 作者:行者123 更新时间:2023-12-01 01:03:59 25 4
gpt4 key购买 nike

我正在使用 Nodejs,并且希望每天早上 5:30 和晚上 11:30 触发一个函数。

我应该如何遵循这种方法。

我还想添加除上述之外的更多时间,例如晚上 9:45、下午 5:30

我已经检查https://www.npmjs.com/package/node-schedule尝试过但没有得到任何运气。

var j = schedule.scheduleJob('* * * 23 07 00', function () {
console.log('The answer to life, the universe, and everything!');
});
j.schedule()

谢谢。

最佳答案

您指定了错误的计划模式。

更易读的方法是使用这样的对象:

const j = schedule.scheduleJob({hour: 5, minute: 30}, () => {
console.log('Job runs every day at 5:30AM');
});

如果您需要在一天中的不同时间运行多个作业 - 创建一些具有不同时间模式的作业,并在每个作业中使用相同的功能。

关于javascript - 每日特定时间nodejs触发函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55798481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com