jdk1.8 dynamically and accurately obtain the last day of each month

Timestamp date = DateUtil.parseYYYYMM("2020-06");
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//The last day of the month
LocalDate lastDay =localDate.with(TemporalAdjusters.lastDayOfMonth());

System.out.println("-------------------"+localDate.getYear()+"-"+localDate.getMonth().getValue()+"-"+lastDay.getDayOfMonth());

 

Output result:

-------------------2020-6-30

 

Guess you like

Origin blog.csdn.net/qq_33767353/article/details/108336021