setInterval By the minute On the minute
问题 To the javascript enthusiasts, how would you program a setTimeOut (or setInterval ) handle to fire by the minute on the minute. So for example, if it is the 51 second of the current time, then fire it in 9 seconds, if it is the 14th second then fire it in 46 seconds thanks 回答1: var date = new Date(); setTimeout(function() { setInterval(myFunction, 60000); myFunction(); }, (60 - date.getSeconds()) * 1000); Obviously this isn't 100% precise, but for the majority of cases it should be sufficient