java获取当前时间的上一个月底的时间

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_20009015/article/details/86704572

/**
* @Author laixiaoxing
* @Description //获取当前时间的上一个月底的时间
* @Date 上午1:57 2019/1/27
*/
private Date getLastMonthFinallyDate(Date begin) {
Instant instant = begin.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
//当前月份日期
LocalDateTime LocalBegin = instant.atZone(zoneId).toLocalDateTime();
//上个月的日期
LocalDateTime localDateLast = LocalBegin.minusMonths(1);
//上个月最后一天的日期
LocalDateTime lastDay = localDateLast.withDayOfMonth(localDateLast.toLocalDate().lengthOfMonth());
ZonedDateTime zdt = lastDay.atZone(zoneId);
return Date.from(zdt.toInstant());
}

猜你喜欢

转载自blog.csdn.net/qq_20009015/article/details/86704572