在Flipclock.js中更改日期

时间:2014-09-05 12:58:14

标签: javascript jquery

我需要Flipclock.js的帮助我不了解Jquery,这个插件让我疯了。我只需要将日期更改为2014年11月23日下午6点,但我似乎无法弄明白。

这是我的代码

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() + 1, 0, 1);

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

1 个答案:

答案 0 :(得分:7)

您正在设置未来日期'而不是添加1年设置完成时间使用:

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

mdn documentation for date

var clock; 
$(document).ready(function() {
    // Grab the current date 
    var currentDate = new Date(); 
    // Set some date in the future. ***change to desired date***
    //var futureDate = new Date(2014, 11, 23, 6, 0, 0); 
    var futureDate = new Date(2014, 10, 23, 18, 0, 0); //fixed as per comments
    // 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 }); 
});