jQuery Date "Invalid Date"

Asked

Viewed 192 times

1

I have a countdown function that works regularly on Google Chrome

var now = new Date();
var countTo = new Date("9 July 2015 14:30:00:00");
alert(countTo);
$('.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;
    }
});

But I gave a alert(countTo); in Firefox and got the message Invalid Date. Basically this script serves to make the comparison with a date x and generate the countdown.

  • 1

    I think there’s an extra 00 on the date. try with new Date("9 July 2015 14:30:00 GMT");

2 answers

2


Rafael.

Try using this date format.

var countTo = new Date("2015/07/09 10:00:00");

1

Just remove the milliseconds that works on IE, FF, and CH:

var countTo = new Date("9 July 2015 14:30:00");
alert(countTo);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.