Sunrise Sunset

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


Updated Wed, 07 Dec 2022 11:56:03 +0000

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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.
Moon and Sun positions are computed using JPL ephemerides (DE440).
east longitude and latitude of the observer can be found in:
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).
Vallado D. A.; Fundamentals of Astrodynamics and Applications; McGraw-Hill, New York; 4th edition (2013).

Cite As

Meysam Mahooti (2023). Sunrise Sunset (, 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_SunriseSunset.m, SinAlt.m, Mjday.m, and invjday.m were modified, and JPL DE430 was replaced with JPL DE440.

test_Sunset.m is modified

The DE430 full matrix is added.

Revised on March 17, 2020.

The image is added.