想放置时间计时器

Would Like to place Time ticker

本文关键字:计时器 时间      更新时间:2023-09-26

我想附加一个基于下午4点CT的计时器,请求任何有JQuery/JavaScript知识的人来帮助我

var now = new Date();//get local time
var hrs = 16-(now.getUTCHours()-5);// convert local to UTC and then CST and checks time differnce with 4CT
var min = 60-now.getUTCMinutes();
这里的

JSFiddle

使用setInterval

http://jsfiddle.net/gSRcN/2/

Javascript

//ticker function that will refresh our display every second
function tick() {
    var now = new Date(); //get local time
    var hrs = 16 - (now.getUTCHours() -5); // convert local to UTC and then CST and checks time differnce with 4CT
    var min = 60 - now.getUTCMinutes();
    var sec = 60 - now.getUTCSeconds();
    if (min > 0) {
        hrs = hrs - 1;
    }
    document.getElementById('time_ticker').innerHTML = hrs + ':' + min + ':' + sec;
}

//the runner
var t = setInterval(tick, 1000);
HTML

<div id="primaryProductAvailability">
    <div class="short-message-block">   <span>Availability: </span><span class="message availability in-stock">In Stock</span>
    </div>
    <div class="long-message-block">    <span class="message in-stock">Ships same day if ordered before 4pm CT</span>
    </div>
</div>
<span id="time_ticker"></span>