1. 创建两个LocalDate对象
LocalDate startDate = LocalDate.parse("2020-10-25");
LocalDate now = LocalDate.now();
2. 你可能想到的获取天数方式
Period period = Period.between(startDate, now);
System.out.println("period.getDays: " + period.getDays());
输出结果:
period.getDays: 0
3. 正确的获取方式
// 方式一
long days = now.toEpochDay() - startDate.toEpochDay();
// 方式二
long days1 = startDate.until(now, ChronoUnit.DAYS);
System.out.println("days: " + days);
System.out.println("days: " + days1);
输出结果:
days: 92
days: 92