獲取上個月第一天和最後一天:
LocalDateTime date = LocalDateTime.now().minusMonths(1);
LocalDateTime firstday = date.with(TemporalAdjusters.firstDayOfMonth());
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
System.out.println("firstday:"+firstday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
System.out.println("lastDay:"+lastDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
獲取當前月第一天和最後一天
LocalDateTime date = LocalDateTime.now();
LocalDateTime firstday = date.with(TemporalAdjusters.firstDayOfMonth());
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
System.out.println("firstday:"+firstday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
System.out.println("lastDay:"+lastDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));