Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: SV: Add date


Message #1 by "Robert Nyman" <robert.nyman@c...> on Tue, 22 Oct 2002 14:40:20 +0200
> If you say 
> 
> new Date("07/32/2002")
> 
> you will get back a date of August 1,2002(date object expects 
> month first, then day).

or new Date(year, month-1, day)

> for example:
> 
> var myDate=new Date("07/02/2002");
> var myDayOfMonth=myDate.getDate();
> myDate.setUTCDate(myDayOfMonth+30);

Since you use getDate() in the previous line, it's better to use setDate()
instead of setUTCDate(), or you'll have surprise :)

> alert(myDate.toDateString());
> 
> will give you "Thu Aug 1 2002".
> 
> If you want it in the original form, then for instance:
> 
> myRealMonth=(myDate.getMonth()+1)%12; //for some unknown 
> reason, months are zero-based

%2 doesn't seem to be really necessary, does it?

  Return to Index