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
Random Developer
source
to share
3 answers
It is zero-based. January - month 0.
http://www.w3schools.com/jsref/jsref_getMonth.asp
+9
Chris farmer
source
to share
getMonth () starts at 0.
+4
Nick presta
source
to share
The enumeration is 0 based.
0 = January
1 = Feb .... etc.
+1
Quintin robinson
source
to share