Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am confused about working with javascript dates

Status
Not open for further replies.

kingpoop

Programmer
Sep 11, 2001
7
US
Hi, I don't understand why the month
portion of the code below produces a
month of 2 instead of 3. Can anyone
help me understand why this is happening?
Thank you for your help
kp

<script language=&quot;javascript&quot;>
var now = new Date();
var day = now.getDate();
var month = now.getMonth();
var year = now.getFullYear();
alert('now = ' + now);
alert('day = ' + day);
alert('month = ' + month);
alert('year = ' + year);
</script>

Produces:
day = 10
month = 2 why is this 2 instead of 3 ?
year = 2002
 
This method returns an integer (0 for January thru 11 for December) that represents the month for the specified date.

Its like using an array where the integer represents the position (starting at position 0) with in the array.

Example MyArray(&quot;JAN&quot;, &quot;FEB&quot;, &quot;MAR&quot;, .......)

MyArray(0) would return Jan
MyArray(1) would return Feb
etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top