gpt4 book ai didi

javascript - FlipClock 倒计时器显示给定日期和时间错误

转载 作者:行者123 更新时间:2023-11-28 06:37:50 25 4
gpt4 key购买 nike

我正在使用 jQuery FlipClock显示给定日期时间的倒计时器。因此,为了在 FlipClock 中显示给定日期和时间的倒计时器,我得到了 this关联。 就我而言,结束日期是

8th December 2015, 12:0:0

因此,根据上面的链接,我编写了这样的代码

 var date  = new Date(Date.UTC(2015, 12, 8, 12, 0, 0));
var now = new Date();
var diff = date.getTime()/1000 - now.getTime()/1000;
var clock;
clock = $('.clock').FlipClock({
clockFace: 'DailyCounter',
autoStart: false,
callbacks: {
stop: function() {
$('.message').html('The clock has stopped!')
}
}
});
clock.setTime(diff);
clock.setCountdown(true);
clock.start();

<div class="clock"></div>

但是它显示的倒计时日期是错误的。那么我可以知道为什么我会收到此错误吗?如何解决问题?任何建议或意见都非常值得赞赏。谢谢

这是我的 fiddle链接

最佳答案

问题是因为 Date.UTC 中的月份是从零开始的

 var date  = new Date(Date.UTC(2015, 11, 8, 12, 0, 0)); //11 for Dec

请参阅文档 ( http://www.w3schools.com/jsref/jsref_utc.asp )

month : Required. An integer representing the month Expected values are 0-11, but other values are allowed:

-1 will result in the last month of the previous year

12 will result in the first month of the next year

13 will result in the second of the next year

演示:http://jsfiddle.net/kishoresahas/cqgw1mb3/7

关于javascript - FlipClock 倒计时器显示给定日期和时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com