Java Date Time Java Java API
java.time.Year
public boolean isLeap()
Checks if this year object is a leap year.
public static boolean isLeap(long year)
Checks if the provided year is a leap year.
package com.logicbig.example.year;import java.time.Year;public class IsLeapExample { public static void main(String... args) { Year y = Year.of(2011); System.out.println(y); boolean b = y.isLeap(); System.out.println(b); Year y2 = Year.of(2020); System.out.println(y2); boolean b2 = y2.isLeap(); System.out.println(b2); }}
2011false2020true
package com.logicbig.example.year;import java.time.Year;public class IsLeapExample2 { public static void main(String... args) { boolean b = Year.isLeap(2011); System.out.println(b); boolean b2 = Year.isLeap(2020); System.out.println(b2); }}
falsetrue