-3
jQuery(document).ready( function($){
    var newDate = new Date( 2016 , 2 , 28 , 8 , 0 , 0 , 0 );
    alert( $.fn.jquery );
    $('#countdown-ex1').countdown({until: newDate});
});

results in:

enter image description here


where as

var newDate = new Date( 2016 , 1 , 28 , 8 , 0 , 0 , 0 );

results in:

enter image description here

jQuery Version: 1.11.3


TL;DR;

Month 2 equals March

Month 1 equals February

Now is this a bug or on purpose? And why would that be on purpose?

Community
  • 1
  • 1
deW1
  • 5,562
  • 10
  • 38
  • 54
  • Month values are zero based, ie. `0` = Jan, `1` = Feb... – Rory McCrossan Feb 23 '16 at 20:29
  • 3
    Yes, they are 0 based.... Surely you should have realized this on your own. – Travis J Feb 23 '16 at 20:31
  • @TravisJ why would they be 0 based if the year and day isn't that's what I don't get – deW1 Feb 23 '16 at 20:33
  • 1
    I think this answer explain this well. http://programmers.stackexchange.com/questions/179285/why-does-javascript-treat-days-and-months-differently – Mosh Feu Feb 23 '16 at 20:37
  • 1
    One reason would be that days and years have no names. Whereas months do. So that means binding months to a 0 based indexed array of names is straight forward. That and many other explanations here from Jon Skeet: http://stackoverflow.com/a/344400/1026459; however, the general outlook there is "don't worry about the why". Also, this is a topic which has been covered many times, there are several duplicates on the site, and it is easily googleable. – Travis J Feb 23 '16 at 20:38

3 Answers3

0

Month values are zero based, ie. 0 = Jan, 1 = Feb, and so on. To get the dates you expect just reduce the Month values by 1:

jQuery(document).ready( function($){
    var newDate = new Date( 2016 , 1 , 28 , 8 , 0 , 0 , 0 ); // 28 Feb 2016
    alert( $.fn.jquery );
    $('#countdown-ex1').countdown({until: newDate});
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

Read some documentation on JS Date objects:

http://www.w3schools.com/jsref/jsref_obj_date.asp

particularly the bit about months being 0 to 11..

Spacedman
  • 92,590
  • 12
  • 140
  • 224
-1

date's month is on 0 base. http://www.w3schools.com/jsref/jsref_getmonth.asp

The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135