Javascript: Moon and Sun rise and set

[ Root ]

This page contains an implementation of the Montenbruck and Pfleger sunrise / moonrise / twilight algorithm in JavaScript. The algorithm is described in detail elsewhere in this site and should work for all latitudes even within the (ant) arctic circles. There will be a 'fuzzy zone' at around latitude 67.43 as a result of using approximate Sun postion routines - and a similar zone around the 'lunar arctic circle' - but real rise and set times depend strongly on your local horizon anyway. Treat any 'days' or 'nights' shorter than about 20 minutes with caution.

View the source of this page to see the Javascript code. Save this page to your computer to run the code offline - you don't need to visit this Web address to be able to use the page! This page has been tested on Netscape 4.7x, Netscape 6.2, MS Internet Explorer 6 and Opera 7.

Fill in the boxes below and click 'calculate' to generate your table
Year : Answers believed to be useable for 50 years either side of 2000
Month : No error checking on correct months, days and leap years yet.
Day :
Longitude : Decimal degrees west longitudes must be negative
Time Zone : Decimal hours west of or 'behind' Greenwich negative
Latitude : Decimal degrees south negative
Number of days : How many lines in the table? (365 lines take about a minute on an elderly PC)
Click to run : : Use reset to clear table to calculate for a new location
Results :
Copy and paste!

Keith Burnett 3rd Jan 03 (It's snowing!)