-2

I am using FlipClock.js to have a countdown clock till new year day. I want to change this to countdown to 8am local time on the first. I am a bit confused as to how to do this.

Here is the script I am currently using:

var clock;
$(function() {
  var currentDate = new Date();
  var futureDate  = new Date(currentDate.getFullYear() + 1, 0, 1);
  var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
  clock = $('.clock').FlipClock(diff, {
    clockFace: 'DailyCounter',
    countdown: true
  });
});

EDIT

I tried changing my code to this:

var clock;
$(function() {
  var currentDate = new Date();
  var futureDate  = new Date(Date.UTC(2014, 0, 01, 08, 0, 0));
  var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
  clock = $('.clock').FlipClock(diff, {
    clockFace: 'DailyCounter',
    countdown: true
  });
});

This line

var futureDate  = new Date(currentDate.getFullYear() + 1, 0, 1);

was changed to this line:

var futureDate  = new Date(Date.UTC(2014, 0, 01, 08, 0, 0));

When I did this it added one hour to the countdown clock. It should of added more since the time was 12am to 8am. What did I do wrong and how do I correct it?

4

1 回答 1

1

如前所述Lix,您应该修改futureDate. 如果您对此有疑问,我的建议是阅读DateJavascript 语言中的预定义对象。这是一个很好的参考

对象的有效定义之一Date如下所示:

new Date(year, month [, day, hour, minute, second, millisecond]);

成功找到明年(currentDate.getFullYear() + 1)之后,您所要做的就是正确填写其余参数。

当心- 在 JavascriptDate对象中,相对于其余月份而言,只有一个月是违反直觉的:0-11.

于 2013-12-29T01:42:29.903 回答