// Determines if a given year is a leap year according to the Julian Calendar
// up to 1582 then proceeds with the Gregorian calendar from 1582 onwards.
// Expects year as integer and returns true or false if it is a leap year or not.
public static boolean isLeapYear(int year) {
GregorianCalendar cal = new GregorianCalendar();
cal.set(GregorianCalendar.YEAR, year);
return cal.getActualMaximum(GregorianCalendar.DAY_OF_YEAR) > 365;
}
Posted: March 20, 2023
Return to the snippets listing