Easily calculate sunrise, sunset and twilight (civil, nautical and
astronomical) times using Java with the jSunTimes package.
Latest version: 1.0 (12th June 2011)
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 email@example.com.
- v0.3 - 6th March 2005
- jsuntimes-0.2.jar (66kB)
- jsuntimes-0.1.jar (65kB)
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:
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:
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.
- 1.0 - 12th June 2011
- Fixed problem with converting Time objects to Strings when time has seconds ≥ 59.5 (was showing seconds as 60).
- Fixed problem where Julian dates weren't being converted to midday (12:00:00) - necessary for the algorithm to produce accurate results.
- Added eight new methods to the Sun class to allow the phenomena times to be calculated without the need to first convert a Calendar to a Julian date. This should simplify things a little bit!
- Updated javadoc.
- 0.3 - 6th March 2005
- Fixed longitude sign (should have been negative for longitudes west of the Greenwich Meridian
- Updated Javadoc
- 0.2 - 13th April 2004
- Added uk.me.jstott.util.JulianDateConverter utility class to convert the date and time held in a Calendar object to a Julian date.
- Changed time zone handling to use the TimeZone class.
- Added SunTimesApp and SunTimesApplet to provide a GUI to calculate sunrise, sunset and twilight times.
- Provided a link to the SunTimesApp application as a Java Web Start link.
- 0.1 - 31st March 2004
- Initial Version.
Licensing and Warranty
This software is provided without warranty of any kind and I cannot be held responsible for any loss occured by errors in the software.
© 2000-11, Jonathan Stott.
19 Jan 2019 07:23:25 GMT