2

如何使用 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;
    }
});
4

1 回答 1

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

我希望这是有道理的!如果您想查看实时版本,这里有一个小提琴。

您还可以使用 jQuery 查看这个倒数计时器

于 2013-09-17T19:22:02.490 回答