Javascript returns month as 9 where 10

I am creating today date using onclick event in JavaScript. When I set the .value property with:

var now = new Date;
...Value = now.getMonth() + "/" + now.getDate() + "/" + now.getYear(); 

      

this gives: 9/9/2009 I expect: 10/9/2009

This happens in both IE and Firefox. The system time on my computer is correct. Any ideas?

+2


source to share


3 answers


It is zero-based. January - month 0.



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

+9


source


getMonth () starts at 0.



+4


source


The enumeration is 0 based.

0 = January
1 = Feb .... etc.

+1


source







All Articles