homepage Welcome to WebmasterWorld Guest from 54.166.173.147
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript date returning wrong month
caffinated




msg:4332293
 11:07 pm on Jun 28, 2011 (gmt 0)

I'm sure someone will point out a logical reason for this. I don't understand why the following code is alerting 16th August 2011 and not 16th July?


var x=new Date(2011,07,16);
alert(x);

 

penders




msg:4332310
 11:43 pm on Jun 28, 2011 (gmt 0)

Because the month (2nd param) is an integer in the range 0 (January) to 11 (December), not 1 to 12 as you are expecting. So, 7 indicates the 8th month of August.

The day (3rd param) is the usual 1 to 31. But all other params start at 0.

caffinated




msg:4332315
 11:57 pm on Jun 28, 2011 (gmt 0)

Many thanks penders.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved