Close

Java Date Time - LocalDate.isLeapYear() Examples

Java Date Time Java Java API 


Class:

java.time.LocalDate

java.lang.Objectjava.lang.Objectjava.time.LocalDatejava.time.LocalDatejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.time.chrono.ChronoLocalDateChronoLocalDatejava.io.SerializableSerializableLogicBig

Method:

public boolean isLeapYear()


Checks if this year of the local date is a leap year.

According to ISO-8601 standards, a year is a leap year if:

It is divisible by 4.

It is not not divisible by 100.

But if divisible by 400, it is a leap year.

For example, 1904 was a leap year because it is divisible by 4.

1900 was not a leap year as it is divisible by 100,

2000 was a leap year as it is divisible by 400.


Examples


package com.logicbig.example.localdate;

import java.time.LocalDate;

public class IsLeapYearExample {

public static void main (String... args) {
LocalDate d = LocalDate.of(2000, 1, 2);
boolean leapYear = d.isLeapYear();
System.out.println(leapYear);

LocalDate d2 = LocalDate.of(2005, 1, 2);
boolean leapYear2 = d2.isLeapYear();
System.out.println(leapYear2);

}
}

Output

true
false




See Also