2015-10-14 48 views
-2

個小時天分秒負荷爲0只個小時天分秒負荷只有

<html 
<span id="countdown"></span> 

<script> 

// set the date we're counting down to 
var target_date = new Date("Jan 15, 2016").getTime(); 

// variables for time units 
var days, hours, minutes, seconds; 

// get tag element 
var countdown = document.getElementById("countdown"); 

// update the tag with id "countdown" every 1 second 
setInterval(function() { 

    // find the amount of "seconds" between now and target 
    var current_date = new Date().getTime(); 
    var seconds_left = (target_date - current_date)/1000; 

    // do some time calculations 
    days = parseInt(seconds_left/86400); 
    seconds_left = seconds_left % 86400; 

    hours = parseInt(seconds_left/3600); 
    seconds_left = seconds_left % 3600; 

    minutes = parseInt(seconds_left/60); 
    seconds = parseInt(seconds_left % 60); 

    // format countdown string + set tag value 
    countdown.innerHTML = days + "d, " + hours + "h, " 
    + minutes + "m, " + seconds + "s"; 

}, 1000); 

</script> 
+0

請首先糾正你的HTML標籤,所以它有一個關閉'>'。另外,請讓你的問題更清楚。你在哪裏獲得'0'的價值? – nameless

+4

有問題嗎? – gefei

回答

0

是沒有問題的!一切工作正常。

// set the date we're counting down to 
 
var ex_target_date = new Date("Jan 15, 2016").getTime(); 
 
var target_date = new Date(2016 , 0 , 15 , 0 , 0 , 0).getTime();// <--- this is preferable 
 

 
document.write('<hr>ex_target_date : ' + ex_target_date + '<br>'); 
 
document.write('ex_target_date : ' + target_date + '<hr>'); 
 

 

 
// variables for time units 
 
var days, hours, minutes, seconds; 
 

 
// get tag element 
 
var countdown = document.getElementById("countdown"); 
 

 
// update the tag with id "countdown" every 1 second 
 
setInterval(function() { 
 

 
    // find the amount of "seconds" between now and target 
 
    var current_date = new Date().getTime(); 
 
    var seconds_left = (target_date - current_date)/1000; 
 

 
    // do some time calculations 
 
    days = parseInt(seconds_left/86400); 
 
    seconds_left = seconds_left % 86400; 
 

 
    hours = parseInt(seconds_left/3600); 
 
    seconds_left = seconds_left % 3600; 
 

 
    minutes = parseInt(seconds_left/60); 
 
    seconds = parseInt(seconds_left % 60); 
 

 
    // format countdown string + set tag value 
 
    countdown.innerHTML = days + "d, " + hours + "h, " 
 
    + minutes + "m, " + seconds + "s"; 
 

 
}, 1000);
<span id="countdown"></span>

+0

我同意 - 可以在您的計算機上檢查系統日期嗎?你有沒有改變到1月15日? – pherris

+0

不,我不知道!我沒有修改你的代碼 – Anonymous0day

+0

我同意你的答案Anonymous0day ...要求OP檢查他們的系統時鐘 – pherris

相關問題