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

The source code can be found at GitHub and is distributed under the terms of Apache License 2.0.


commons-suncalc is available at Maven Central. Just add this snippet to your pom.xml:


Or use this snippet in your build.gradle (e.g. in Android Studio):

dependencies {

Quick Start

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

Date date = // date of calculation
double lat, lng = // geolocation
SunTimes times = SunTimes.compute()
            .on(date)       // set a date
            .at(lat, lng)   // set a location
            .execute();     // get the results
System.out.println("Sunrise: " + times.getRise());
System.out.println("Sunset: " + times.getSet());

Dependencies and Requirements

commons-suncalc requires at least Java 7, but has no other dependencies. It can also be used on Android (API level 19 or higher).