这是我用于计数器的代码,所以它将在24小时后重复(循环)。
我在Github上找到的。
<script type='text/javascript'>
jQuery(document).ready(function($){
$(function(){
var nextDay = new Date(). setHours(0, 0, 0, 0) + (1 * 24 * 60 * 60 * 1000);
$('#clock').countdown(nextDay, function(event) {
$(this).html(event.strftime(''
+ '<div><span class="number">%D</span> <span class="timertext">days</span></div>'
+ '<div><span class="number">%H</span> <span class="timertext">hours</span></div>'
+ '<div><span class="number">%M</span> <span class="timertext">mins</span></div>'
+ '<div><span class="number">%S</span> <span class="timertext">secs</span></div>'
));
});
});
});
试试这个var nextYear = moment.tz("2018-30-12 00:00", "US/Central");
,它工作得很好,不确定如何在var nextDay = new Date(). setHours(0, 0, 0, 0) + (1 * 24 * 60 * 60 * 1000);
上使用。
我希望计数器以特定的时区显示。例如,US/Central。我使用MomentJS。
发布于 2018-12-07 04:38:50
//offset would be how many hours off from UTC, e.g CST = -6, GMT/UTC = 0
var offset = -6;
var coun = true;
//Below is a looper every second.
setInterval(newDay, 100);
function newDay(){
var d = new Date();
var curTime = (d.getUTCHours() + offset)+""+d.getUTCMinutes();
if((curTime == "0000") && (coun == true)){
//Insert javascript needed here
coun = false;
//the above variable stops the inserted javascript repeating.
}
else if(curTime != "0000"){
coun = true;
}
}
希望这能有所帮助。
https://stackoverflow.com/questions/53658966
复制相似问题