2015-07-02 49 views
-1

任何人都可以幫我嗎?例如,我要一個countdown timer但反向的,例如:倒數倒數

我插入我的日期和時間在JavaScript或MySQL(無所謂),它會算..

例子:我插:01/07/2015年

今天的計數器顯示:1天1小時19分鐘

+0

我用了t他的劇本:http://stackoverflow.com/questions/7853179/simple-php-javascript-countdown-to-datetime – thecreator

+0

下來倒我們通常叫** **起來 –

+0

@thecreator所以如果你使用的腳本什麼是您的問題 – depperm

回答

1

如果你不想使用jQuery的,那麼你可以做這樣的事情:

var startTime = +new Date("07/01/2015"); // m/d/Y gets timestamp in ms 
 

 
var second = 1000; 
 
var minute = second * 60; 
 
var hour = minute * 60; 
 
var day = hour * 24; 
 

 
var element = document.getElementById('timer'); // target element for the timer 
 

 
function countUp() { 
 
    // time between now and the start date 
 
    var time = Date.now() - startTime; 
 

 
    // days passed since start 
 
    var days = Math.floor(time/day); 
 
    time -= days * day; 
 

 
    // hours passed 
 
    var hours = Math.floor(time/hour); 
 
    time -= hours * hour; 
 

 
    // minutes passed 
 
    var minutes = Math.floor(time/minute); 
 

 
    // update element 
 
    element.innerHTML = days + 'day ' + hours + 'hour ' + minutes + 'min'; 
 

 
    setTimeout(countUp, minute); 
 
}; 
 

 
countUp();
<span id="timer"></span>

1

既然你想使用jQuery的倒計時插件,你可以使用它的內置計數功能。查看jQuery倒計時頁面的'Count Up'選項卡:http://keith-wood.name/countdown.html

編輯:添加代碼示例

$("#countdown").countdown({since: new Date(2015, 7-1, 1)});
#countdown { 
 
    float: left; 
 
    width: 240px; 
 
}
<link href="http://keith-wood.name/css/jquery.countdown.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="http://keith-wood.name/js/jquery.plugin.js"></script> 
 
<script src="http://keith-wood.name/js/jquery.countdown.js"></script> 
 

 
<span id="countdown">