利用Java8中的 isLeapYear() 方法可以非常容易判断某个年份是否是闰年,具体用法如下:

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Main
{
public static void main(String[] args)
{
// 1. ZonedDateTime

ZonedDateTime currentTime = ZonedDateTime.now();

if (currentTime.toLocalDate().isLeapYear())
{
System.out.println(currentTime.getYear() + " 是闰年");
} else {
System.out.println(currentTime.getYear() + " 不是闰年");
}

// 2. LocalDateTime

DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTime = LocalDateTime.parse("2020-11-17 15:36:18", formatter1);

if (localDateTime.toLocalDate().isLeapYear())
{
System.out.println(localDateTime.getYear() + " 是闰年");
} else {
System.out.println(localDateTime.getYear() + " 不是闰年");
}

// 3. LocalDate

DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse("2020-11-17", formatter2);

if (localDate.isLeapYear())
{
System.out.println(localDate.getYear() + " 是闰年");
} else {
System.out.println(localDate.getYear() + " 不是闰年");
}

//4. Check current year is leap year or not

if (Year.now().isLeap())
{
System.out.println("当前年份 是闰年");
} else {
System.out.println("当前年份 不是闰年");
}
}
}

欢迎在评论中提出你的问题,学习愉快。