嗨,我已經安裝了該插件有一個倒數計時器有:的jQuery秒轉換爲這種格式
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor((t/1000) % 60);
var minutes = Math.floor((t/1000/60) % 60);
var hours = Math.floor((t/(1000 * 60 * 60)) % 24);
var days = Math.floor(t/(1000 * 60 * 60 * 24));
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function initializeClock(id, endtime) {
var clock = document.getElementById(id);
var daysSpan = clock.querySelector('.days');
var hoursSpan = clock.querySelector('.hours');
var minutesSpan = clock.querySelector('.minutes');
var secondsSpan = clock.querySelector('.seconds');
function updateClock() {
var t = getTimeRemaining(endtime);
daysSpan.innerHTML = t.days;
hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
if (t.total <= 0) {
clearInterval(timeinterval);
}
}
updateClock();
var timeinterval = setInterval(updateClock, 1000);
}
var deadline = new Date(Date.parse(new Date()) + 1 * 60 * 60 * 1000);
initializeClock('clockdiv', deadline);
我有它運行基於秒的倒計時代碼..
所以我想從上面的代碼格式寫我的代碼,在幾秒鐘內到截止日期。
var gdtesttime = 00:15:00; //hh:mm:ss
var a = gdtesttime.split(':'); // split it at the colons
var gdseconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 ; //seconds
我需要在這2個主要行的幫助:
var deadline = new Date(Date.parse(new Date()) + 1 * 60 * 60 * 1000);
2.var t = Date.parse(endtime) - Date.parse(new Date());
這是我的HTML:
<div id="clockdiv" class="pull-right">
<span><img src="assets/images/timer.png" /></span>
<div class="disp-none">
<span class="days"></span>
<div class="smalltext">Days</div>
</div>
<div>
<span class="hours"></span><span>:</span>
</div>
<div>
<span class="minutes"></span><span>:</span>
</div>
<div>
<span class="seconds"></span>
</div>
</div>
JS提琴:https://jsfiddle.net/k4b81x8c/
您可以創建小提琴? –
它很好,你可以用JSFiddle創建 – Minesh
https://jsfiddle.net/k4b81x8c/這裏是倒計時計時器@MuhammadAkberKhan –