上周所有日期:
List<String> getLastWeeks(){
List<String> lastWeek = new ArrayList<>();
LocalDate current = LocalDate.parse("2023-04-04");
int week = current.getDayOfWeek().getValue();
if(week != 1){
current = current.minusDays(week - 1);
}
for (int i =7;i >= 1; i--){
lastWeek.add(current.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
return lastWeek;
}
上个月的所有日期:
List<String> lastMonthDay = new ArrayList<>();
LocalDate last = LocalDate.parse("2023-04-04").minusMonths(1);
int days = last.lengthOfMonth();
last = last.minusDays(last.getMonthValue());
for (int i = 0; i <days; i++){
lastMonthDay.add(last.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
return lastMonthDay;
2498

被折叠的 条评论
为什么被折叠?



