0

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?

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

i will it said i had to wait 1 minute :)
in the vein of "teach them to fish" here's a tip more constructive than "basic debugging." If you use Chrome, you can open the Developer Tools tool (built in) and click the Console tab. In it, you can actually type live JavaScript code - for example, when I ran new Date(2014, 5, 01, 0); I immediately noticed Tue Jul 01 2014 00:00:00 GMT-0400 (EDT) and not the intended June. This is a good technique for trying individual lines of code at a time. All of the modern browsers have some form of Developer Tools or JavaScript Console available to this end. Cheers!

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.