Java LocalDate isLeapYear() Method
Example
Check if the years 2024 and 2026 are leap years:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2024, 1, 15);
LocalDate date2 = LocalDate.of(2026, 1, 15);
System.out.println(date1.isLeapYear());
System.out.println(date2.isLeapYear());
}
}
Definition and Usage
The isLeapYear() method checks if the year of the date is a leap year (a year with 366 days, where February has 29 days).
A year is a leap year if it can be divided by 4. Years that can be divided by 100 are not leap years, unless they can also be divided by 400. So 2024 and 2000 are leap years, but 2026 and 1900 are not.
Syntax
public boolean isLeapYear()
Parameter Values
None.
Technical Details
| Returns: | true if the year is a leap year, otherwise false. |
|---|
Related Pages
❮ Date and Time Methods