import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class TimeUtil {
/**
* 偏移天数到当日 23:59:59
*
* @param offsetDay 偏移天数
* @return LocalDateTime
*/
public static LocalDateTime getOffsetDay(Integer offsetDay) {
LocalDateTime localDateTime = LocalDateTimeUtil.of(DateUtil.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
return localDateTime.plusDays(offsetDay).withHour(23).withMinute(59).withSecond(59);
}
/**
* 偏移天数到当日 23:59:59
*
* @param month 偏移月数
* @param time 时间
* @return LocalDateTime
*/
public static LocalDateTime getOffsetMonth(Integer month,LocalDateTime time) {
LocalDateTime localDateTime = LocalDateTimeUtil.of(DateUtil.parse(time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
return localDateTime.plusMonths(month).withHour(23).withMinute(59).withSecond(59);
}
}
hutool工具实现时间偏移到23点59分59秒
于 2023-01-12 10:59:12 首次发布