Easily calculate sunrise, sunset and twilight (civil, nautical and astronomical) times using Java with the jSunTimes package.
Latest version: 1.0 (12th June 2011)

Download | Documentation | Web Start | Examples | Version History | Licensing

The jSunTimes package provides an API to calculate sunrise, sunset and twilight (civil, nautical and astronomical) times using Java. You are able to specify the exact latitude and longitude of the location to calculate the times for and can also specify the time zone and whether to take daylight savings time (summer time) into account. The package also contains a Julian date conversion class so that you can convert the date/time held in a Calendar instance to a Julian date. The package also contains classes so that you can run the calculations as an applet or as a standalone application.

The algorithms used in the package are based on functions available at http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html.

Bear in mind that jSunTimes is still in development, so check back often for updates. To contact me about jSunTimes, send an e-mail to jsuntimes@jstott.me.uk.


Current Version

Previous Versions


Java Web Start Application

An online interface to jSunTimes is provided with a Java Web Start application. When run, this will display a window into which you can enter your latitude and longitude, the date, your time zone and whether daylight savings time applies. Then click the Go button in order to display the sunrise, sunset and twilight times.


The Sun class is easy to use. Remember that the jsuntimes-1.0.jar file should appear on your classpath before you can compile your code that uses it. Also remember that you have to import the package:

import uk.me.jstott.sun.*;

The SunTest class contains examples of calculating sunrise/sunset/twilight times for a couple of places.

To include the jSunTimes applet in a webpage, use the following applet element in your web page:

<applet code="uk.me.jstott.sun.SunTimesApplet.class"

You can download the jar file to your website, but make sure that you change the codebase and archive attributes to match your site and the current version of jSunTimes.

Version History

Licensing and Warranty

This software product is available under the GNU General Public License (GPL). Source code and documentation are provided in the jar file and on the website.

This software is provided without warranty of any kind and I cannot be held responsible for any loss occured by errors in the software.

Save up to $90 with Dreamhost