From ff273fbcde958bd8fe8539d509304fc2a2f1bec9 Mon Sep 17 00:00:00 2001 From: seahi Date: Tue, 12 Nov 2024 09:41:23 +0800 Subject: [PATCH] LocalDate --- src/chapter5/Example21.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/chapter5/Example21.java b/src/chapter5/Example21.java index c58ab85..c3e4c56 100644 --- a/src/chapter5/Example21.java +++ b/src/chapter5/Example21.java @@ -1,4 +1,24 @@ package chapter5; +import java.time.LocalDate; + public class Example21 { + public static void main(String[] args) { + LocalDate now = LocalDate.now(); + LocalDate of = LocalDate.of(2015, 12, 12); + + System.out.println("今年是" + now.getYear() + "年"); + System.out.println("月份:" + now.getMonth()); + System.out.println("月份:" + now.getMonthValue()); + System.out.println("日期:" + now.getDayOfMonth()); + System.out.println("今年中的第几天:" + now.getDayOfYear()); + System.out.println("周几:" + now.getDayOfWeek()); + + System.out.println("====判断相关的方法===="); + + System.out.println("of是否在now之前?" + of.isBefore(now)); + System.out.println("of是否在now之后?" + of.isAfter(now)); + System.out.println("of和now是否相等?" + of.isEqual(now)); + System.out.println("of是否闰年?" + of.isLeapYear()); + } }