/**
* 将一个日期字符串转换为前一个月的最后一天
* @param yyyyMMdd
* @return
*/
public static String timeConversion(String yyyyMMdd) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate date;
try {
date = LocalDate.parse(yyyyMMdd, formatter);
} catch (java.time.format.DateTimeParseException e) {
logger.error("timeConversion解析时间异常: " + e.getMessage());
throw new IllegalArgumentException("输入的日期格式不正确", e);
}
YearMonth yearMonth = YearMonth.from(date);
LocalDate lastDayOfPrevMonth = yearMonth.minusMonths(1).atEndOfMonth();
return lastDayOfPrevMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
将一个日期字符串转换为前一个月的最后一天
最新推荐文章于 2024-04-30 16:46:47 发布