# LocalDate

# 获取当前年月日

import java.time.LocalDate;

public class LocalDateTest {
    public static void main(String[] args) {
        LocalDate now = LocalDate.now();
        System.out.println("当前系统时间:" + now);
        System.out.println("年:" + now.getYear());
        System.out.println("月:" + now.getMonth().getValue());
        System.out.println("日:" + now.getDayOfMonth());
        System.out.println("周几:" + now.getDayOfWeek().getValue());
    }
}

# 修改日期

import java.time.LocalDate;

public class LocalDateTest {

    public static void main(String[] args) {
        LocalDate now = LocalDate.now();
        System.out.println("当前系统时间:" + now);

        //修改年份
        LocalDate newDate = now.withYear(2099);
        System.out.println("修改后的年月日:" + newDate);

        //修改月份
        LocalDate newMonth = now.withMonth(12);
        System.out.println("修改后的月:" + newMonth);

        //增加天数
        LocalDate newDays = now.plusDays(20);
        System.out.println("增加的天数:" + newDays);

        //减少月份
        LocalDate minusMonths = now.minusMonths(2);
        System.out.println("减去的月份:" + minusMonths);


        //获取指定的日期
        LocalDate ofDate = LocalDate.of(2022, 1, 1);
        System.out.println(ofDate);

        //判断日期是不是之前
        System.out.println("日期是否在 now 之后:" + (ofDate.isBefore(now) == true ? "在之前" : "不在之前"));

        //判断日期是不是之后
        System.out.println("日期是否在 now 之后:" + (ofDate.isAfter(now) == true ? "在之后" : "不在之后"));

        //判断日期是不是相等
        System.out.println("日期是否相等:" + (ofDate.equals(now) == true ? "相等" : "不相等"));
    }
}