|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.sop.common.util;
|
|
|
|
|
|
+import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
@@ -112,20 +113,6 @@ public class DateDisposeUtils extends DateUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- String d1 = "2020-01-01";
|
|
|
- String d2 = "2020/01/01";
|
|
|
- String d3 = "2020-01-01 12:00";
|
|
|
- String d4 = "2020/01/01 12:00";
|
|
|
- String d5 = "2020/01/01 12:00:00";
|
|
|
- String d6 = "2020/01/01 12:00:00";
|
|
|
- System.out.println(parseDate(d1).getTime());
|
|
|
- System.out.println(parseDate(d2).getTime());
|
|
|
- System.out.println(parseDate(d3).getTime());
|
|
|
- System.out.println(parseDate(d4).getTime());
|
|
|
- System.out.println(parseDate(d5).getTime());
|
|
|
- System.out.println(parseDate(d6).getTime());
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 获取服务器启动时间
|
|
@@ -203,7 +190,7 @@ public class DateDisposeUtils extends DateUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询两个日期之间的所有日期集合
|
|
|
+ * 查询两个日期之间的所有日期集合(包括开始时间和结束时间当天)
|
|
|
*
|
|
|
* @param startTime 1693497600000L
|
|
|
* @param endTime 1693756800000L
|
|
@@ -220,15 +207,24 @@ public class DateDisposeUtils extends DateUtils {
|
|
|
|
|
|
Calendar tempStart = Calendar.getInstance();
|
|
|
tempStart.setTime(start);
|
|
|
+ tempStart.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ tempStart.set(Calendar.MINUTE, 0);
|
|
|
+ tempStart.set(Calendar.SECOND, 0);
|
|
|
+ tempStart.set(Calendar.MILLISECOND, 0);
|
|
|
+ long x1 = tempStart.getTimeInMillis();
|
|
|
|
|
|
Calendar tempEnd = Calendar.getInstance();
|
|
|
tempEnd.setTime(end);
|
|
|
-// tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
|
|
|
+ tempEnd.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ tempEnd.set(Calendar.MINUTE, 0);
|
|
|
+ tempEnd.set(Calendar.SECOND, 0);
|
|
|
+ tempEnd.set(Calendar.MILLISECOND, 0);
|
|
|
+ long x2 = tempEnd.getTimeInMillis();
|
|
|
+
|
|
|
while (tempStart.before(tempEnd) || tempStart.equals(tempEnd)) {
|
|
|
days.add(dateFormat.format(tempStart.getTime()));
|
|
|
tempStart.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
}
|
|
|
-
|
|
|
return days;
|
|
|
}
|
|
|
|
|
@@ -241,4 +237,24 @@ public class DateDisposeUtils extends DateUtils {
|
|
|
public static LocalDate timestampToLocalDate(Long time) {
|
|
|
return Instant.ofEpochMilli(time).atZone(ZoneOffset.ofHours(8)).toLocalDate();
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+// String d1 = "2020-01-01";
|
|
|
+// String d2 = "2020/01/01";
|
|
|
+// String d3 = "2020-01-01 12:00";
|
|
|
+// String d4 = "2020/01/01 12:00";
|
|
|
+// String d5 = "2020/01/01 12:00:00";
|
|
|
+// String d6 = "2020/01/01 12:00:00";
|
|
|
+// System.out.println(parseDate(d1).getTime());
|
|
|
+// System.out.println(parseDate(d2).getTime());
|
|
|
+// System.out.println(parseDate(d3).getTime());
|
|
|
+// System.out.println(parseDate(d4).getTime());
|
|
|
+// System.out.println(parseDate(d5).getTime());
|
|
|
+// System.out.println(parseDate(d6).getTime());
|
|
|
+ long l1 = 1699613541562L;
|
|
|
+ long l2 = 1699863530000L;
|
|
|
+ System.out.println(DateFormatUtils.format(l1, SystemConstant.DEFAULT_DATE_PATTERN));
|
|
|
+ System.out.println(DateFormatUtils.format(l2, SystemConstant.DEFAULT_DATE_PATTERN));
|
|
|
+ System.out.println(getDaysBetween(l1, l2, SystemConstant.DEFAULT_DATE_YMD_S_PATTERN));
|
|
|
+ }
|
|
|
}
|