30天
LocalDate localDate = LocalDate.now();
LocalDate afterDate = localDate.minusDays(30);
// 获取倒数30天
List<LocalDateTime> localDateTimes = new ArrayList<>(30);
for (LocalDate currentdate = afterDate; currentdate.isBefore(localDate) || currentdate.isEqual(localDate); currentdate = currentdate.plusDays(1)) {
localDateTimes.add(LocalDateTime.of(currentdate.getYear(), currentdate.getMonth(), currentdate.getDayOfMonth(), 0, 0));
}
12个月
LocalDate localDate = LocalDate.now();
LocalDate afterDate = localDate.minusMonths(12);
// 获取倒数12个月
List<LocalDateTime> localDateTimes = new ArrayList<>(30);
for (LocalDate currentdate = afterDate; currentdate.isBefore(localDate) || currentdate.isEqual(localDate); currentdate = currentdate.plusMonths(1)) {
localDateTimes.add(LocalDateTime.of(currentdate.getYear(), currentdate.getMonth(), 1, 0, 0));
}