3

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

1
  • In JavaScript while using Date constructor month starts from 0, So to set October you need to pass 10-1. Commented Oct 5, 2016 at 13:45

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

1 Comment

Ahh so was almost there, good thing to know :) thanks for that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.