Java判断两个时间段是否有交集
2021-05-17 18:29
标签:ring amp format public sim 判断 overlap mat stat public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return } Java判断两个时间段是否有交集 标签:ring amp format public sim 判断 overlap mat stat 原文地址:https://www.cnblogs.com/zhanggaosong/p/9746215.html
private static boolean isOverlap(String startdate1, String enddate1,String startdate2, String enddate2) {
Date leftStartDate = null;
Date leftEndDate = null;
Date rightStartDate = null;
Date rightEndDate = null;
try {
leftStartDate = format.parse(startdate1);
leftEndDate = format.parse(enddate1);
rightStartDate = format.parse(startdate2);
rightEndDate = format.parse(enddate2);
} catch (ParseException e) {
return false;
}
((leftStartDate.getTime() >= rightStartDate.getTime())
&& leftStartDate.getTime() ||
((leftStartDate.getTime() > rightStartDate.getTime())
&& leftStartDate.getTime() ||
((rightStartDate.getTime() >= leftStartDate.getTime())
&& rightStartDate.getTime() ||
((rightStartDate.getTime() > leftStartDate.getTime())
&& rightStartDate.getTime()