Joe Bobby
Joe Bobby

Reputation: 2811

Setting Date in Javascript

I downloaded this countdown script from themeforest and the author isnt too responsive. I'm trying to set the countdown script to count down to June 1st, 2014 but for some reason its currently displaying 117 days.. here is the script:

// init countdown
    var countdown_time = $("#countdown-widget").data('time');
    var countdown_timezone = $("#countdown-widget").data('timezone');

    if(countdown_time != '') {
        launchTime = new Date(Date.parse(countdown_time));
    }else{
        launchTime = new Date(2014, 6, 01, 0); // Set launch: [year], [month], [day], [hour]...
        //launchTime.setDate(launchTime.getDate() + 15); // Add 15 days
    }
    if(countdown_timezone == '')
        countdown_timezone = null;

    $("#countdown-widget").countdown({
        until: launchTime,
        format: "dHMS",
        labels: ['','','','','','',''],
        digits:['0','1','2','3','4','5','6','7','8','9'],
        timezone: countdown_timezone,
        onTick: _onTick
    });

what did i do wrong?

Upvotes: 0

Views: 69

Answers (1)

Scott Heaberlin
Scott Heaberlin

Reputation: 3424

In the JavaScript Date constructor, the month value should be "zero based". This means you need to add one to whatever you really want - for example, January is 0, not 1. Because of this, you are actually calculating to July 1, 2014, which is 118 days (here in my Eastern US time zone, GMT-5) from the date of this post. I am assuming you are ahead of me in the time zone world :)

Try this:

launchTime = new Date(2014, 5, 01, 0);

Upvotes: 1

Related Questions