The hutool tool realizes the time offset to 23:59:59

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);
	}

}

Guess you like

Origin blog.csdn.net/qq_37741426/article/details/128655700