In this source code example, we show you how to check for leaf year in Java 8.
Check for leaf year in Java 8
package com.ramesh.java8.datetime;
import java.time.LocalDate;
/**
* Useful Java8DateUtiliy Methods
* @author javaguides.net
*
*/
public final class Java8DateUtility {
/**
* Check for leap year.
*/
public static void checkLeapYear() {
LocalDate today = LocalDate.now();
if (today.isLeapYear()) {
System.out.println("This year is Leap year");
} else {
System.out.println("Current year is not a Leap year");
}
}
}
JUnit test case
package com.ramesh.java8.datetime;
import org.junit.Test;
/**
* JUnit test cases for Java8DateUtiliy Methods
* @author javaguides.net
*
*/
public class Java8DateUtilityTest {
@Test
public void checkLeafYear() {
Java8DateUtility.checkLeafYear();
}
}
Run the JUnit test cases will print the output:
Current year is not a Leap year