LocalDate操作日期
LocalDate操作日期
public static void main(String[] args) {// 获取当前日期LocalDate currentDate = LocalDate.now();System.out.println("今天的日期: " + currentDate);// 获取一个月前的日期LocalDate localDate = currentDate.minusMonths(1);System.out.println("一个月前的日期: " + localDate);// 定义一个字符串日期String strDate = "2023-02-25";// 使用DateTimeFormatter定义日期格式DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");// 解析字符串日期为LocalDate类型并输出LocalDate date = LocalDate.parse(strDate, formatter);System.out.println(localDate.compareTo(date));}