在做数据统计时经常涉及到月的第一天和最后一天的时间。
LocalDateTime dateTime = LocalDateTime.parse("2019-04-03T14:00");
//获取月的第一天
LocalDateTime firstDay = dateTime.with(TemporalAdjusters.firstDayOfMonth());
//获取月的最后一天
LocalDateTime lastDay = dateTime.with(TemporalAdjusters.lastDayOfMonth());
//获取月的第一天0时0分0秒
LocalDateTime firstDay = dateTime.with(TemporalAdjusters.firstDayOfMonth())
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0);
//获取月的最后一天的23点59分59秒
LocalDateTime lastDay = dateTime.with(TemporalAdjusters.lastDayOfMonth())
.withHour(23)
.withMinute(59)
.withSecond(59);