0
我目前有一個倒數計時器,每24小時重置一次,但現在它顯示「NaN」而不是時間。我有一種感覺,這可能與變量有關嗎?倒數計時器,不顯示時間
有人可以幫我糾正問題可能是什麼?
// Set the date we're counting down to
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var today = new Date();
var day = today.getDate();
var month = today.getMonth() ;
var year = today.getFullYear();
//alert(year); You can check the year from here
var countDownDate = new Date(monthNames[month] + day + "2017 24: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);
if(hours < 10){
var hours = "0" + hours;
}
if(minutes<10){
var minutes = "0" + minutes;
}
if(seconds <10){
var seconds = "0" + seconds;
}
// Output the result in an element with id="demo"
document.getElementById("H_one").innerHTML = hours ;
document.getElementById("M_one").innerHTML = minutes;
document.getElementById("s_one").innerHTML = seconds ;
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);