Sun/Moon Rise/Set

Rising and setting times of the Sun and the Moon and twilight times


Updated Wed, 07 Dec 2022 10:40:52 +0000

View License

Year, month, day, lambda (Geographic east longitude of the observer in [deg]), phi (Geographic latitude of the observer in [deg]), zone (local time - universal time in [h]) and twilight (Indicates civil, nautical or astronomical twilight) are received, then rising and setting times of the Sun and the Moon and twilight times are computed.
east longitude and latitude of the observer can be found at:
local time - universal time is available here (daylight saving time is considered):
Montenbruck O., Pfleger T.; Astronomy on the Personal Computer; Springer Verlag, Heidelberg; 4th edition (2000).

Cite As

Meysam Mahooti (2023). Sun/Moon Rise/Set (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Quad.m was modified.


test_Sunset.m, Mjday.m, and invjday.m were modified.

The header of SunPos.m and MoonPos.m are modified.

Accuracy is improved using planetary positions (SunPos.m and MoonPos.m) with respect to true equator and equinox of date rather than mean equator and equinox of date.

SinAlt.m is modified and CityName.m is added to give the name of city you have entered its geographical latitude and longitude.
Description is updated.
The image is added.
Quad.m is improved.