【发布时间】:2019-08-02 05:00:54
【问题描述】:
我做了一个javascript倒计时,效果很好。但我希望它每天重新启动两次,因为我每天运送两次订单。 太平洋标准时间上午 1 点至上午 11 点 太平洋标准时间下午 2-4 点
我希望它在时钟时间太平洋标准时间下午 4 点之后显示太平洋标准时间上午 11 点的倒计时时间,并且在上午 11 点之后它应该重置并显示下午 4 点的倒计时,并且在太平洋标准时间下午 4 点之后它应该重置并显示太平洋标准时间晚上 11 点的倒计时
这是我的倒计时代码。
// Set the date we're counting down to
var countDownDate = new Date("July 26, 2019 11:00:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and 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("demo").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("demo").innerHTML = "EXPIRED";
}
}, 1000);
<p id="demo"></p>
【问题讨论】:
-
重置您的
countDownDate,而不是“过期”操作。 -
这就是混乱,我很困惑如何重新启动它并在上午 11 点结束,然后在下午 4 点结束,然后在上午 11 点结束
-
你能帮我修改一下代码吗?
标签: javascript json ajax