Date and time arithmetic
- From: "Sam Hobbs" <samuel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 17 Apr 2005 19:17:32 -0700
How to advance a date and time by 29 days, 12 hours and 44 minutes? That
period of time is a lunar month; see:
http://encarta.msn.com/encyclopedia_761573665/Moon.html
The last new moon was April 8 at 20:34 UTC and the next new moon will be May
8 at 8:48 UTC; see:
http://sunearth.gsfc.nasa.gov/eclipse/phase/phases.1999-2010.html
I have tried a variety of ways to do the calculation. I have searched this
newsgroup and I have looked at J R Stockton's pages; see:
http://www.merlyn.demon.co.uk/js-dates.htm
The code below is my last attempt. This works, except the time is about a
half hour too far. I assume the result should be 08:48:00 UTC but I get
09:18:00 UTC.
var Start
Start = new Date(Date.UTC(2005, 3, 8, 20, 34));
WScript.echo(Start.toUTCString());
with (Start) {
setDate(getDate()+29);
setHours(getHours()+12);
setMinutes(getMinutes()+44);
}
WScript.echo(Start.toUTCString());
My results are:
Fri, 8 Apr 2005 20:34:00 UTC
Sun, 8 May 2005 09:18:00 UTC
.
- Follow-Ups:
- Re: Date and time arithmetic
- From: Vic Sowers
- Re: Date and time arithmetic
- From: Trevor L.
- Re: Date and time arithmetic
- Prev by Date: RE: Dynamic drop down in javascript
- Next by Date: Wrong version of jscript.dll (5.1.0.8513)
- Previous by thread: IFrame and Logon page
- Next by thread: Re: Date and time arithmetic
- Index(es):
Relevant Pages
|
Loading