我发现了一个适合我的Web项目的倒计时。我希望倒计时在每个星期五的上午9点重新开始。有人可以给我一个提示吗?这是代码:
(function(){
const days = document.getElementById("days");
const hours = document.getElementById("hours");
const minutes = document.getElementById("minutes");
const seconds = document.getElementById("seconds");
const currentDate = new Date().getFullYear();
const concertDate = new Date(`June 19 ${currentDate} 09:00:00`);
function updateCountdown() {
const currentTime = new Date();
const diff = concertDate - currentTime;
const d = Math.floor(diff / 1000 / 60 / 60 / 24);
const h = Math.floor(diff / 1000 / 60 / 60) % 24;
const m = Math.floor(diff / 1000 / 60) % 60;
const s = Math.floor(diff / 1000) % 60;
days.innerHTML = d;
hours.innerHTML = h < 10 ? "0" + h : h;
minutes.innerHTML = m < 10 ? "0" + m : m;
seconds.innerHTML = s < 10 ? "0" + s : s;
}
setInterval(updateCountdown, 1000);
})();
您可以使用[cron]:https://www.npmjs.com/package/cron;
您的计划时间应为0 9 * * 5