我希望每 5 分钟运行一个函数,即 08:05、08:10、08:15 等......全天
我该如何适应:
setTimeout(function(){
xxxxxxx()
}, 300000);
检测当前时间 - 如果是 5 的倍数则运行 xxxxxx() 函数?
最佳答案
使用setInterval
每秒调用该函数。
然后使用当前时间的过滤器,其中分钟可被 5 整除,秒为零。
var timer = 0;
timer = setInterval(function(){
var currentdate = new Date();
if(currentdate.getMinutes() % 5 == 0 && currentdate.getSeconds() == 0) {
console.log("Alarm");
}
}, 1000);
//to stop: clearInterval(timer);
关于javascript - JQuery 在 5,10,15...55 整点后每 5 分钟运行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58340627/