在一天中的特定时间做某事

Pix*_*ded 2 javascript time date

如何在特定时间和日期触发功能.例如:每周三8:30.我能想到的解决方案是以间隔检查时间,但是循环是滞后的,尤其是当您必须每分钟检查时.有没有替代解决方案.请帮忙,谢谢.

Mat*_*ows 6

就像是...

var dateItHappens = new Date()
// ... set the dateItHappens variable up ...
var millisTillOccurence = dateItHappens.getTime() - new Date().getTime();
setTimeout(function(){ /* ... function you want to call ... */ }, millisTillOccurence);
Run Code Online (Sandbox Code Playgroud)