想放置时间自动收报机

时间:2014-06-17 12:26:02

标签: javascript jquery

我想附加一个基于4Pm 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 Here

1 个答案:

答案 0 :(得分:0)

使用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>

我添加了秒,让自动收报机更加生动。