SunCalc is a simple Java project that calculates the sunrise and sunset times based on geographic location and date. The project uses astronomical formulas to accurately calculate the sunrise and sunset times.
References:
- Java Development Kit (JDK) 8 or higher
The project is organized into the following classes:
SunCalc
: Main class that performs the sunrise and sunset calculations.Location
: Class representing the geographic location with latitude, longitude, and time zone (UTC).TimeUtils
: Utility class containing time conversion methods.SunriseAndSunset
: Class containing themain
method to run the application with examples.
To use the project, follow these steps:
- Compile and run the
SunriseAndSunset
class in your favorite Java IDE. - Configure the location for which you want to calculate the sunrise and sunset times in the
SunriseAndSunset
class. Set the latitude, longitude, and UTC values in theLocation
object. - Run the application, and the sunrise and sunset times will be printed to the console.
Here's an example of how to set up a Location
object and use the SunCalc
class:
Location location = new Location();
location.setLatitude(-33.2394434);
location.setLongitude(-60.318236);
location.setUtc(-3);
LocalDate day = LocalDate.now();
SunCalc sunCalculator = new SunCalc(day);
LocalTime sunrise = sunCalculator.calculateSunriseHour(location);
LocalTime sunset = sunCalculator.calculateSunsetHour(location);
System.out.println("Sunrise: " + sunrise);
System.out.println("Sunset: " + sunset);