admin管理员组

文章数量:1334291

Using a countdown plugin but I think I'm setting the date and time wrong.

Code:

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(2016,10,27, 10,00,00);
    // 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
    });
});

I'm attempting this:

var futureDate = new Date(2016,10,27, 10,00,00);

Which is 27th October 2016 at 10am

Coding up 52 days though so I must be doing something wrong

Using a countdown plugin but I think I'm setting the date and time wrong.

Code:

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(2016,10,27, 10,00,00);
    // 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
    });
});

I'm attempting this:

var futureDate = new Date(2016,10,27, 10,00,00);

Which is 27th October 2016 at 10am

Coding up 52 days though so I must be doing something wrong

Share Improve this question edited Oct 5, 2016 at 14:02 StephenTG 2,6676 gold badges28 silver badges37 bronze badges asked Oct 5, 2016 at 13:42 JamesJames 1,7061 gold badge21 silver badges54 bronze badges 1
  • In JavaScript while using Date constructor month starts from 0, So to set October you need to pass 10-1. – Satpal Commented Oct 5, 2016 at 13:45
Add a ment  | 

1 Answer 1

Reset to default 7

Which is 27th October 2016 at 10am

That's where you're going wrong. Months in JavaScript are 0-indexed (January is 0, December is 11), the 10th month is actually November.

var futureDate = new Date(2016,9,27,10,00,00);

本文标签: Setting a set date with javascriptStack Overflow