日期工具类 DateTools
Posted mengjianzhou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日期工具类 DateTools相关的知识,希望对你有一定的参考价值。
为了跟其他日期工具类进行区分起名字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; } }
以上是关于日期工具类 DateTools的主要内容,如果未能解决你的问题,请参考以下文章
elasticsearch代码片段,及工具类SearchEsUtil.java
如何从片段中调用 getSupportFragmentManager()?