JavaScript 如何在每天特定时间刷新一组代码

How to refresh a group of code everyday at a particular time in JavaScript

因为我是初学者。我需要帮助。我在这个平台上看到了一些类似的答案。但是,我不太确定他们是否解决了我的问题:

如何在每天的特定时间刷新页面或制作特定的一组代码运行?

谢谢

你可以试试这个方法

setInterval(function() {
    // Code you would like to run every 10 seconds (10000 milliseconds)
}, 10000)

或在特定时间(来源 Call a javascript function at a specific time of day

var now = new Date();
var millisTill10 = new Date(now.getFullYear(), now.getMonth(), 
now.getDate(), 10, 0, 0, 0) - now;
if (millisTill10 < 0) {
     millisTill10 += 86400000; // it's after 10am, try 10am tomorrow.
}
setInterval(function() {
    // Runs at 10am
}, millisTill10)