0
我有一些計時器的代碼是基於moment.js 一旦計時器計數到零我希望它重新啓動。如果我手動插入日期和時間,它工作正常,但如果我稱之爲最初使用它只是停留在00:00:00自動重啓的moment.js計時器
價值中的代碼如下所示:
var cutOff = moment.tz(targetDate+ ' ' + targetTime, "Europe/London");
$('#timer').countdown(cutOff.toDate(), function(event) {
var days = (event.strftime('%D'));
if (days >0){
var str = '<span class="timerLabel"> DAYS </span>' + '<span class="timerLabel"> HRS </span>' + '<span class="timerLabel"> MINS </span>' + '<span class="timerLabel"> SECS </span>';
var str2 = '<div class="numberCircle"><span>'+ (event.strftime('%D')) + '</span></div>' + '<span class="separator"> : </span>' + '<div class="numberCircle"><span>'+ (event.strftime('%H')) + '</span></div>' + '<span class="separator"> : </span>' + '<div class="numberCircle"><span>' + (event.strftime('%M')) + '</span></div>' + '<span class="separator"> : </span>' + '<div class="numberCircle"><span>' + (event.strftime('%S')) + '</span></div>';
}else{
var str = '<span class="timerLabel"> HRS </span>' + '<span class="timerLabel"> MINS </span>' + '<span class="timerLabel"> SECS </span>';
var str2 = '<div class="numberCircle"><span>'+ (event.strftime('%H')) + '</span></div>' + '<span class="separator"> : </span>' + '<div class="numberCircle"><span>' + (event.strftime('%M')) + '</span></div>' + '<span class="separator"> : </span>' + '<div class="numberCircle"><span>' + (event.strftime('%S')) + '</span></div>';
}
var str3 = '<div class="timerbreak"></div>'
var str4 = '<span class="TimeLeft">Time Left for </span>' + despatchday;
var str5 = '<span class="delmethod">Choose preferred despatch method on checkout</span>'
document.getElementById('countdownTimer').innerHTML = str; //The labels
document.getElementById('countdownTimer2').innerHTML = str2; // The countdown
document.getElementById('countdownTimer3').innerHTML = str3; // The underline
document.getElementById('countdownTimer4').innerHTML = str4;
document.getElementById('countdownTimer5').innerHTML = str5;
})
.on('finish.countdown', function(event) {
$(this).parent()
//targetDate = moment().add(1, 'days').format('YYYY-MM-DD');
cutOff = moment.tz(targetDate+ ' ' + targetTime, "Europe/London");
despatchday = 'Despatch Tomorrow';
$('div#timer').countdown(cutOff);
//$('div#timer').countdown("2017-05-09 16:00:00");
}) ;
爲什麼使用
$('div#timer').countdown("2017-05-09 16:00:00");
但使用
$('div#timer').countdown(cutOff);
嘗試使用'cutOff.format()'而不是隻使用'cutOff' – Santosh
@Santosh結果NaN:NaN:NaN –
您可以嘗試傳遞格式爲'format(「YYYY-MM-DD HH:mm:ss 「);'...它應該以指定的格式返回字符串。我現在沒有筆記本電腦,所以不能自己嘗試。 – Santosh