views:

79

answers:

3

I'm building today's date using a onclick event in JavaScript. When i set the .value property with:

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

this produces: 9/9/2009 I am expecting: 10/9/2009

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

+4  A: 

getMonth() starts at 0.

Nick Presta
+9  A: 

It's zero-based. January is month 0.

http://www.w3schools.com/jsref/jsref%5FgetMonth.asp

Chris Farmer
Thanks, this was driving me nuts.
Ioxp
+1  A: 

The enumeration is 0 based.

0 = January
1 = Feb... etc

Quintin Robinson