Signup/Sign In

Java LocalDate isLeapYear() Method

Java isLeapYear() method is used to check if a date is a leap year or not. It checks the leap year, according to the ISO proleptic calendar system rules.

A year is a leap year if it is divisible by four without leaving the remainder. For example, 2004 is a leap year it is divisible by 4. 1900 was not a leap year as it is divisible by 100.

This method does not take any argument and returns either true or false. The syntax of the method is given below.

Syntax

public boolean isLeapYear()

Parameters:

It does not take any parameter.

Returns:

It returns either true or false.

Time for an Example:

Let's take an example to check whether a year is a leap year or not. Here, we have a year 2015 which is not leap year that's why the method returns false.

import java.time.LocalDate; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(2015, 10, 21);
		System.out.println(localDate);
		boolean d  = localDate.isLeapYear();
		System.out.println("Is leap Year : "+d);
	}
}


2015-10-21
Is leap Year : false

Time for another Example:

Let's take another example to understand the use of the isLeapYear() method. Here, we have a year that and checking by using the method, that returns true.

import java.time.LocalDate; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(2020, 10, 21);
		System.out.println(localDate);
		boolean d  = localDate.isLeapYear();
		System.out.println("Is leap Year : "+d);
	}
}


2020-10-21
Is leap Year : true

Live Example:

Try with a live example, execute the code instantly with our powerful Online Java Compiler.



About the author:
I am a 3rd-year Computer Science Engineering student at Vellore Institute of Technology. I like to play around with new technologies and love to code.