24小时后按时区循环计数

时间:2018-12-06 20:12:34

标签: javascript jquery countdown

那是我用于计数器的代码,因此它将在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);上使用。

我希望计数器显示在特定的时区。例如,美国/中部。我使用MomentJS

1 个答案:

答案 0 :(得分:0)

//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;
  }
}

希望这会有所帮助。