Tomas Alonso Rehor
Tomas Alonso Rehor

Reputation: 265

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

Upvotes: 0

Views: 318

Answers (2)

dhorelik
dhorelik

Reputation: 1507

You can simply pass a date to the countdown

var date = '2016/10/01';

$("#defaultCountdown")
    .countdown(date, function(event) {
        $(this).text(
            event.strftime('%D days %H:%M:%S')
        );
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.countdown/2.1.0/jquery.countdown.min.js"></script>

<div id="defaultCountdown"></div>

strftime() gives you a way to format your output

Upvotes: 1

Spencer Wieczorek
Spencer Wieczorek

Reputation: 21565

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

Upvotes: 1

Related Questions