0

I'm trying to show a simple countdown from 2 hours like so:

$(function () {

    var timeout = new Date(20000); 

    $('#countdown').countdown({until: timeout, compact: true, format: 'HMS'});
});

However I just get 00:00:00, any ideas why?

2
  • Have you read the docs? It says: There are four ways of instantiating a date: var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds); Commented Jun 23, 2012 at 13:27
  • @Michael Yes I have read the docs, but not everyone is a JavaScript expert and understands this as naturally as others! Commented Jun 23, 2012 at 13:28

1 Answer 1

4

You get 00:00:00, because new Date(20000); is actually

Thu Jan 01 1970 00:00:20 GMT+0000 (GMT)

like 40 years ago. :D What you need to do is either:

var timeout = new Date(Date.now() + 20000);

or

var timeout = 20000;

By the way: two hours is not 20000, it is

1000 (ms) * 60 (s) * 60 (min) * 2 == 7200000
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.