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?
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
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);