Search code examples
javascriptjqueryhtmlcountdown

Simple jQuery countdown


I have a very simple problem, but the official documentation and online help wasn't enough to help me with this.

I have this template countdown that counts days remaining until the new year.

I just want to change it so it counts to October 1st of 2016.

var PageComingSoon = function () {
    return {
      //Coming Soon
      initPageComingSoon: function () {
            var newYear = new Date();   
            newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1);
            $('#defaultCountdown').countdown({until: newYear})
        }
    };
}();

Solution

  • The first three parameters of are Date(year, month, day, ...). The given code newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1) clearly states that the year is next year, then the first month, and the first day (note months start at 0). You likely can simply change the values of these to represent October the 1st of 2016.

    var myDate = new Date(2016, 9, 1);