如何在经过时不断重新开始倒计时

时间:2018-04-01 19:47:14

标签: javascript countdown countdowntimer

我正在使用倒数计时器脚本,我在网上遇到并略微修改以适合我的网站。这适用于倒计时到设定的日期/时间,但我需要计时器暂停约1小时并继续计数7天。例如,当它到达周三00:00:00结束时,它应该等待一个小时,然后再开始计数直到下周三,依此类推。 - 我需要帮助! - 我使用的代码

function teus(){
// Set the date we're counting down to
var countDownDate = new Date("Apr 3, 2018 18:00:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get todays date and time
var now = new Date().getTime();

// Find the distance between now an the count down date
var distance = countDownDate - now;

// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Output the result in an element with id="demo"
document.getElementById("teu").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s "  +  "";

// If the count down is over, write some text
if (distance < 0) {
    clearInterval(x);
    document.getElementById("teu").innerHTML = "Service Time";

}
}, 1000);
}
teus()

0 个答案:

没有答案