| home | contents | send comment | send link | add bookmark |

## Sunrise, Sunset solver

### version 2

#### by Stephen R. Schmitt

Enter your location:
latitude |  | ° |  | ' | North | South
longitude |  | ° |  | ' | East | West

Enter the date:
`mm/dd/yyyy`
| / |  | / |  |

Solution:
Sunrise |
Sunset |

### Contents

1. About
2. The source code
3. Discussion

#### 1. About

This Java Script calculator determines the time of sunrise and sunset for your location and a given date. To operate the calculator, enter your latitude and longitude. Press the Compute button to obtain the solution. The Test button loads the geographic coordinates of Boston, Massachusetts, USA to demonstrate how the calculator works. On invalid entries, a popup window will display an error message.

Return to Contents

#### 2. The source code

The Java Script source code for this program can be viewed by using the View|Source command of your web browser.

You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitability of this source code for your use.

Return to Contents

#### 3. Discussion

This page calculates the times of sunrise and sunset on any date, accurate to the minute within several centuries of the present. It correctly describes what happens in the Arctic and Antarctic regions, where the Sun may not rise or set on a given date. The program was adapted from a BASIC program in Sky & Telescope magazine, August 1994, page 84,

Sunrise occurs when the rotation of the Earth causes the upper limb of the Sun to move above the visible horizon as seen by an observer on the Earth's surface. Sunset is similar, occurring when the upper limb of the Sun moves below the visible horizon. The mathematical model of the Sun's apparent motion in the sky gives the position of the center of the Sun as it would be seen from the center of the Earth. Because the Sun is very distant from the Earth, it is not necessary to correct for parallax, the angular offset due observation from the Earth's surface. However, it is necessary to account for the visual radius of the Sun since the position of the upper limb determines sunset and sunrise. Additionally, the Earth's atmosphere refracts light noticeably for light source near the horizon. This calculator includes corrections that account for both of these under average conditions. Actual observations of sunset and sunrise may differ from the predicted times due to variations in atmospheric conditions and due to local topography.

The predicted times are given in local time, standard or daylight saving, obtained from your computer's operating system. The azimuth of sunrise and sunset is given, measured in degrees from true North. You must determine your correct latitude and longitude to obtain valid predictions for your location. A good on-line source for this information is Sky & Telescope.

### References

1. Astronomical Algorithms, Meeus
2. Practical Astronomy with your Calculator

Return to Contents

AbCd Classics - free on-line books

Copyright © 2007, Stephen R. Schmitt