Javascript flipclock倒计时到特定时区中的特定日期,无需重置

Javascript flipclock倒计时到特定时区中的特定日期,无需重置,javascript,datetime,countdowntimer,flipclock,Javascript,Datetime,Countdowntimer,Flipclock,我正在尝试使用flipclock创建特定日期的倒计时,而不重置计时器,也不让不同时区的人看到不同的数字。例如,我想倒计时到2月20日凌晨12:00 MST 我的问题是,当浏览器达到0后刷新时,时钟重置,时间显示负数。如果人们以当前配置查看该时钟,则该时钟将在其时区内倒计时至2月20日凌晨12点 我已经从新年倒计时开始,并设置了我的日期,但不知道如何解决时区和重置问题 var clock; $(document).ready(function() { // Grab the curre

我正在尝试使用flipclock创建特定日期的倒计时,而不重置计时器,也不让不同时区的人看到不同的数字。例如,我想倒计时到2月20日凌晨12:00 MST

我的问题是,当浏览器达到0后刷新时,时钟重置,时间显示负数。如果人们以当前配置查看该时钟,则该时钟将在其时区内倒计时至2月20日凌晨12点

我已经从新年倒计时开始,并设置了我的日期,但不知道如何解决时区和重置问题

var clock;

$(document).ready(function() {

    // Grab the current date
    var currentDate = new Date();

    // Set some date in the future. In this case, it's always Jan 1
    var futureDate = new Date(currentDate.getFullYear() + 0, 1, 20, 0, 0);

    // Calculate the difference in seconds between the future and current date
    var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;

    // Instantiate a coutdown FlipClock
    clock = $('.clock').FlipClock(diff, {
        clockFace: 'DailyCounter',
        countdown: true,
        showSeconds: false,
        callbacks: {
            stop: function() {
                $('.message').html('The clock has stopped!');
            }
        }
    });
});

因为你想倒计时的时间是特定时区的特定时间,那么最简单的方法就是倒计时,而不是倒计时

2016年2月20日,美国山地时间为UTC-7,因此:

2016-02-20 00:00:00 MST == 2016-02-20 07:00:00 UTC
所以

我会让别人回答FLIPTH和你的重置问题的细节,尽管你可以考虑单独问这个问题。(以后一次尽量只问一个问题。)

var clock;
$(文档).ready(函数(){
//抓取当前日期
var now=新日期();
var currentDate=新日期(now.getUTCFullYear()、now.getUTCMonth()、now.getUTCDate()、now.getUTCHours()、now.getUTCMinutes()、now.getUTCSeconds());
currentDate.setHours(currentDate.getHours()-7);
//设定未来的某个日期。在这种情况下,总是1月1日
var futureDate=新日期(currentDate.getFullYear()+0,1,20,0,0);
//计算未来日期和当前日期之间的秒差
var diff=futureDate.getTime()/1000-currentDate.getTime()/1000;
//将时差限制为零
如果(差异<0){
差异=0;
}
//实例化一个coutdown FlipClock
时钟=$('.clock')。翻转时钟(不同{
钟面:“DailyCounter”,
倒计时:没错,
showSeconds:false,
回调:{
停止:函数(){
$('.message').html('时钟已停止!');
}
}
});
});
部分解决时区问题(有点难看):

将时间差限制为不小于零的部件:

// Limit time difference to zero
if (diff < 0) {
  diff = 0;
}
//将时差限制为零
如果(差异<0){
差异=0;
}

感谢您详细解释这一点,我用不同的日期处理了这一点,效果很好!
// Grab the current date
var now = new Date();
var currentDate = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),  now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
currentDate.setHours(currentDate.getHours() - 7);
// Limit time difference to zero
if (diff < 0) {
  diff = 0;
}