package com.itheima.demo;import cn.hutool.core.date.DateUtil;import java.util.Date;public class DateTimeTool {public static boolean getTimeLong(Date startDate, Date endDate, Date startTime, Date endTime) {//1.按开始时间和结束时间分组,中间"_"分割,map的key示例:2022-11-01 00:00:00_2022-11-01 16:00:00//2.然后循环map,按"_"分割key获取出查出来的开始时间和结束时间//3.获取开始时间和结束时间的时间戳long startDateLong = startDate.getTime();long endDateLong = endDate.getTime();//startTime和endTime为要同步的时间,前端参数传递过来的,开始时间+1秒,例如要同步2022-11-01 16:00:00加1秒就是2022-11-01 16:00:01//endTime减1秒startTime = DateUtil.offsetSecond(startTime, 1);endTime = DateUtil.offsetSecond(endTime, -1);//获取传递过来的时间戳long startTimeLong = startTime.getTime();long endTimeLong = endTime.getTime();//然后进行判断是否包含,如果包含就返回错误信息if (((startDateLong - startTimeLong) <= 0) && ((endTimeLong - endDateLong) <= 0) ||((endDateLong - startTimeLong) >= 0) && ((startDateLong - endTimeLong) <= 0)) {return true;} else {return false;}}
}