【发布时间】:2020-11-08 18:54:59
【问题描述】:
目前我有一个倒数计时器,唯一的问题是我输入的日期和时间不会与居住在其他地方的人同时结束,因此会将 javascript 解释为他们的时区。有没有办法解决这个问题?当前脚本:
var countDownDate = new Date("Jul 30, 2020 20:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
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);
document.getElementById("countdown").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
document.getElementById("countdown").innerHTML = "EXPIRED";
}
}, 1000);
<p id="countdown"></p>
【问题讨论】:
标签: javascript html countdown clock countdowntimer