Switch branches/tags
Clone or download
shred Remove GitHub ribbon
It links to an external image and thus is not GDPR compliant.
Latest commit a081f77 May 21, 2018
Failed to load latest commit information.
src Remove GitHub ribbon May 21, 2018
.gitignore First commit Apr 27, 2016
.gitlab-ci.yml Use sonar Jan 7, 2017
.project First commit Apr 27, 2016
LICENSE-APL.txt First commit Apr 27, 2016 Change maven central badge Mar 27, 2018
pom.xml Workaround for doxia markdown syntax highlighting Feb 25, 2018

commons-suncalc build status maven central

A Java library for calculation of sun and moon positions and phases.


commons-suncalc version 2 is a complete rewrite, and uses a different set of formulas.

The calculation results of this library are tested against sample results of public astronomical calculator web-sites. However, there may still be errors in the calculations, so please use this first release with care.

See the migration guide for how to migrate from version 1.


  • Lightweight, only requires Java 1.7 or higher, no other dependencies
  • Android compatible, requires API level 19 (KitKat) or higher
  • Available at Maven Central
  • Extensive unit tests


Astronomical calculations are far more complex than throwing a few numbers into an obscure formula and then getting a fully accurate result. There is always a tradeoff between accuracy and computing time.

This library has its focus on getting acceptable results at low cost, so it can also run on mobile devices, or devices with a low computing power. The results have an accuracy of about a minute, which should be good enough for common applications (like sunrise/sunset timers), but is probably not sufficient for astronomical purposes.

If you are looking for the highest possible accuracy, you are looking for a different library.

Quick Start

This library consists of a few models, all of them are invoked the same way:

Date date = // requested date of calculation
double lat, lng = // geolocation
SunPosition position = SunPosition.compute()
        .on(date)       // set a date
        .at(lat, lng)   // set a location
        .execute();     // get the results
System.out.println("Elevation: " + position.getElevation() + "°");
System.out.println("Azimuth: " + position.getAzimuth() + "°");

See the online documentation for API details.


This library bases on:

  • "Astronomy on the Personal Computer", 4th edition, by Oliver Montenbruck and Thomas Pfleger
  • "Astronomical Algorithms" by Jean Meeus
  • MoonIllumination is based on suncalc by Vladimir Agafonkin


  • Fork the Source code at GitHub. Feel free to send pull requests.
  • Found a bug? File a bug report.
  • Are you getting different results from another library or web site? If you file a bug, please try to explain why you think the commons-suncalc result is wrong.


commons-suncalc is open source software. The source code is distributed under the terms of Apache License 2.0.