Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从当前时间戳开始倒计时_Jquery_Timestamp_Countdown_Unix Timestamp - Fatal编程技术网

Jquery 从当前时间戳开始倒计时

Jquery 从当前时间戳开始倒计时,jquery,timestamp,countdown,unix-timestamp,Jquery,Timestamp,Countdown,Unix Timestamp,以下是我正在使用的插件: 从现在开始倒数时,我似乎无法让它工作。我尝试过各种方法,并将我现在拥有的东西放到一个jsfiddle中 我尝试使用其他方法调用当前unix时间戳: 但是,当我试图在最后的倒计时中包含这个或除了已经生成的unix时间戳之外的任何内容时,它会破坏脚本。这个倒计时需要从现在到日期倒计时。如何在这个插件中实现这一点?在这个插件中,您需要将start时间以及now时间设置为当前时间。然后将end时间设置为将来的某个时间 因此,在本例中,倒计时将从当前时间到现在起一小时: /

以下是我正在使用的插件:

从现在开始倒数时,我似乎无法让它工作。我尝试过各种方法,并将我现在拥有的东西放到一个jsfiddle中

我尝试使用其他方法调用当前unix时间戳:


但是,当我试图在最后的倒计时中包含这个或除了已经生成的unix时间戳之外的任何内容时,它会破坏脚本。这个倒计时需要从现在到日期倒计时。如何在这个插件中实现这一点?

在这个插件中,您需要将
start
时间以及
now
时间设置为当前时间。然后将
end
时间设置为将来的某个时间

因此,在本例中,倒计时将从当前时间到现在起一小时:

// This is just used to add hours to the current time in the example below
Date.prototype.addHours= function(h){
    this.setHours(this.getHours()+h);
    return this;
}

$(document).ready(function() {

        var currentTime = new Date();
        var futureTime = (new Date()).addHours(1);

        $('.countdown').final_countdown({
                'start': currentTime.getTime(),
                'end': futureTime.getTime(),
                'now': currentTime.getTime()
        }, function() {
                // Finish Callback
        });
});

JS
.getTime()
返回Javascript时间戳,以毫秒为单位。这意味着您的
现在
值比开始/结束值大1000倍,例如超出范围。谢谢!我能用这个来找出解决办法。最终代码如下:
   var time = Date.now || function() {
       return +new Date;
   };

   $('#timestamp').html( time() );
// This is just used to add hours to the current time in the example below
Date.prototype.addHours= function(h){
    this.setHours(this.getHours()+h);
    return this;
}

$(document).ready(function() {

        var currentTime = new Date();
        var futureTime = (new Date()).addHours(1);

        $('.countdown').final_countdown({
                'start': currentTime.getTime(),
                'end': futureTime.getTime(),
                'now': currentTime.getTime()
        }, function() {
                // Finish Callback
        });
});