Java判断两个时间段是否有交集

2021-05-17 18:29

阅读:429

标签:ring   amp   format   public   sim   判断   overlap   mat   stat   

public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
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;
}

return
((leftStartDate.getTime() >= rightStartDate.getTime())
&& leftStartDate.getTime() ||
((leftStartDate.getTime() > rightStartDate.getTime())
&& leftStartDate.getTime() ||
((rightStartDate.getTime() >= leftStartDate.getTime())
&& rightStartDate.getTime() ||
((rightStartDate.getTime() > leftStartDate.getTime())
&& rightStartDate.getTime()

}

Java判断两个时间段是否有交集

标签:ring   amp   format   public   sim   判断   overlap   mat   stat   

原文地址:https://www.cnblogs.com/zhanggaosong/p/9746215.html


评论


亲,登录后才可以留言!