标签:start efault pre mes put 时间段 tar time public
为了跟其他日期工具类进行区分起名字DateTools
public class DateTools { /** The DAT e_ forma t1. */ public static String DATE_FORMAT1 = "yyyy-MM-dd HH:mm:ss"; /** * 获取两个时间段的交集 * @param s1 * @param e1 * @param s2 * @param e2 * @return */ public static Map<String, LocalDateTime> getOverlapDuration(LocalDateTime s1,LocalDateTime e1,LocalDateTime s2,LocalDateTime e2){ Map<String, LocalDateTime> localDateTimeMap = new HashMap<>(); //是否有交集 long s1InMillis = Timestamp.valueOf(s1).getTime(); long e1InMillis = Timestamp.valueOf(e1).getTime(); long s2InMillis = Timestamp.valueOf(s2).getTime(); long e2InMillis = Timestamp.valueOf(e2).getTime(); long overlapStartTime = 0; long overlapEndTime = 0; if((s1InMillis>=s2InMillis&&s1InMillis<=e2InMillis) ||(e1InMillis>=s2InMillis&&e1InMillis<=e2InMillis)){ overlapStartTime = s1InMillis>=s2InMillis?s1InMillis:s2InMillis; overlapEndTime = e1InMillis<=e2InMillis?e1InMillis:e2InMillis; } LocalDateTime start = LocalDateTime.ofInstant(Instant.ofEpochMilli(overlapStartTime), ZoneId.systemDefault()); LocalDateTime end = LocalDateTime.ofInstant(Instant.ofEpochMilli(overlapEndTime), ZoneId.systemDefault()); localDateTimeMap.put("start", start); localDateTimeMap.put("end" , end); return localDateTimeMap; } }
标签:start efault pre mes put 时间段 tar time public
原文地址:https://www.cnblogs.com/mengjianzhou/p/9066397.html