设置时间倒计时器jquery

时间:2013-09-17 18:12:58

标签: javascript jquery countdown

如何使用Javascript在倒计时中设置EST时间。我使用下面的代码并能够设置小时倒计时,但我需要一个特定的时间作为
http://www.timeanddate.com/countdown/generic?iso=20130920T1730&p0=152/

var now = new Date();
BigDay = new Date("September20,2013");
var countTo=BigDay.getTime()

 $('.timer').countdown(countTo, function(event) {
    var $this = $(this);
    switch(event.type) {
        case "seconds":
        case "minutes":
        case "hours":
        case "days":
        case "weeks":
        case "daysLeft":
            $this.find('span.'+event.type).html(event.value);
            break;
        case "finished":
            $this.hide();
            break;
    }
});

1 个答案:

答案 0 :(得分:5)

这是否与您所寻找的一致?首先,一些HTML:

<span id="days"></span>
<span id="hours"></span>
<span id="minutes"></span>
<span id="seconds"></span>

然后,一些Javascript(连同jQuery!):

setInterval(function(){
    // set whatever future date / time you want here, together with
    // your timezone setting...
    var future = new Date("Sep 20 2014 21:15:00 GMT+0200");
    var now = new Date();
    var difference = Math.floor((future - now) / 1000);

    var seconds = fixIntegers(difference % 60);
    difference = Math.floor(difference / 60);

    var minutes = fixIntegers(difference % 60);
    difference = Math.floor(difference / 60);

    var hours = fixIntegers(difference % 24);
    difference = Math.floor(difference / 24);

    var days = difference;

    $("#seconds").text(seconds + "s");
    $("#minutes").text(minutes + "m");
    $("#hours").text(hours + "h");
    $("#days").text(days + "d");
}, 1000);

function fixIntegers(integer)
{
    if (integer < 0)
        integer = 0;
    if (integer < 10)
        return "0" + integer;
    return "" + integer;
}

我希望这是有道理的! Here's a fiddle如果您希望看到实际版本的实际效果。

您还可以看到此Countdown Timer using jQuery