Home »
Java »
Java Reference »
Java LocalDate Class
Java LocalDate Class | isLeapYear() Method with Example
LocalDate Class isLeapYear() method: Here, we are going to learn about the isLeapYear() method of LocalDate Class with its syntax and example.
Submitted by Preeti Jain, on May 30, 2020
LocalDate Class isLeapYear() method
- isLeapYear() method is available in java.time package.
- isLeapYear() method is used to check whether the year field value is a leap year or not based on ISO Calendar System.
- isLeapYear() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- isLeapYear() method does not throw an exception at the time of checking the status.
Syntax:
public boolean isLeapYear();
Parameter(s):
Return value:
The return type of this method is boolean, it returns true when the year is a leap year otherwise it returns false.
Example:
// Java program to demonstrate the example
// of isLeapYear() method of LocalDate
import java.time.*;
public class IsLeapYearOfLocalDate {
public static void main(String args[]) {
// Instantiates two LocalDate
LocalDate l_da1 = LocalDate.parse("2007-04-04");
LocalDate l_da2 = LocalDate.now();
// Display l_da1,l_da2
System.out.println("LocalDate l_da1 and l_da2: ");
System.out.println("l_da1: " + l_da1);
System.out.println("l_da2: " + l_da2);
System.out.println();
// Here, this method checks whether this
// date l_da1 year is a leap year according
// to ISO Calendar rules or not i.e.
// here it returns false because l_da1
// year (2007) is not a leap year
boolean status = l_da1.isLeapYear();
// Display status
System.out.println("l_da1.isLeapYear(): " + status);
// Here, this method checks whether this
// date l_da2 year is a leap year according
// to ISO Calendar rules or not i.e.
// here it returns true because l_da2
// year (2020) is a leap year
status = l_da2.isLeapYear();
// Display status
System.out.println("l_da2.isLeapYear(): " + status);
}
}
Output
LocalDate l_da1 and l_da2:
l_da1: 2007-04-04
l_da2: 2020-05-30
l_da1.isLeapYear(): false
l_da2.isLeapYear(): true