import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class DateSubtractionExample {
public static void main(String[] args) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 计算2646天前的日期
long daysToSubtract = 2646;
LocalDate resultDate = currentDate.minus(daysToSubtract, ChronoUnit.DAYS);
System.out.println("2646天前的日期为:" + resultDate);
}
}
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class DaysBetweenDatesExample {
public static void main(String[] args) {
// 定义动态日期
LocalDate customDate = LocalDate.of(2018, 6, 6);
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 计算动态日期距离当前日期有多少天
long daysBetween = ChronoUnit.DAYS.between(customDate, currentDate);
System.out.println("距离2018年6月6日已经过去了:" + daysBetween + "天");
}
}