Re: Date and time arithmetic
- From: "Vic Sowers" <Mail@xxxxxxxxxxxxx>
- Date: Mon, 18 Apr 2005 02:13:58 -0500
"Sam Hobbs" <samuel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eI4CIz7QFHA.3356@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>
I did it this way:
moonMins = 44+60*(12+24*29);
Start.setMinutes(Start.getMinutes()+moonMins);
and also got 9:18.
Then I did the date math by hand and, indeed, 9:18 is correct.
I concluded that, since the Earth has moved a bit during the intervening
month, the new moon appears little earlier....
.
- Follow-Ups:
- Re: Date and time arithmetic
- From: Dr John Stockton
- Re: Date and time arithmetic
- From: Sam Hobbs
- Re: Date and time arithmetic
- From: Sam Hobbs
- Re: Date and time arithmetic
- References:
- Date and time arithmetic
- From: Sam Hobbs
- Date and time arithmetic
- Prev by Date: Re: Date and time arithmetic
- Next by Date: launching script from file being nested in another script
- Previous by thread: Re: Date and time arithmetic
- Next by thread: Re: Date and time arithmetic
- Index(es):
Relevant Pages
|