Subtract date to get countdown

2

I currently have the following code:

var now = new Date();
var countTo = 50 * 24 * 60 * 60 * 1000 + now.valueOf();
$('.timer').countdown(countTo, function(event) {
    var $this = $(this);
    switch(event.type) {
        case "seconds":
        case "minutes":
        case "hours":
        case "days":
        case "weeks":
        case "daysLeft":
            $this.find('span.'+event.type).html(event.value);
            break;
        case "finished":
            $this.hide();
            break;
    }
});

Every time I reload the page the count starts again. I would need to set a specific date (14:30:00 08/01/2015) for comparison and countdown for that day.

The count is currently starting at 50 days.

    
asked by anonymous 17.06.2014 / 16:18

1 answer

2

Your code is using the current date (+50 days) for the countdown. If you change the value of this variable to a fixed number (fixed date) then you will get the behavior you want.

For example:

var countTo = new Date('14:30:00 08/01/2015');

I'm not sure exactly what plugin you use, but assuming it's .countdown () of jQuery can see an example here:

link

Note: as "8 January 2015 14:30:00:00" format as my first suggestion can be poorly read if the computer's Locale is different.

    
17.06.2014 / 17:08