From f84d9e69907cb678150eaa6393fd74cf042fcca4 Mon Sep 17 00:00:00 2001
From: zenglf <18502938215@163.com>
Date: 星期四, 28 九月 2023 14:39:03 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into develop

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java |   72 +++++++++++++++++++++++++++++++++++-
 1 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
index 5aa4da8..75c7f8e 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
@@ -1,6 +1,8 @@
 package org.jeecg.modules.mdc.util;
 
 
+import io.swagger.models.auth.In;
+
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.text.ParseException;
@@ -73,10 +75,11 @@
     }
 
     /**
-     * @return 鑾峰彇涓や釜date鐨勬椂闂村樊锛岀粨鏋滀负绉�
+     * @return 鑾峰彇涓や釜date鐨勬椂闂村樊锛岀粨鏋滀负绉� 闄�
      */
     public static long differentSecond(Date startDate, Date endDate) {
-        return (endDate.getTime() - startDate.getTime()) / 1000;
+        return new BigDecimal(endDate.getTime() - startDate.getTime()).divide(new BigDecimal("1000"), 0, BigDecimal.ROUND_HALF_UP).longValue();
+//        return (endDate.getTime() - startDate.getTime()) / 1000;
     }
 
     /**
@@ -162,6 +165,7 @@
     public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS";
     public static final String STR_HHMMSS = "HH:mm:ss";
     public static final String STR_HHMM = "HH:mm";
+    public static final String STR_MMDD = "MM-dd";
 
     /**
      * <p>
@@ -670,6 +674,26 @@
         return list;
     }
 
+    /**
+     * 鑾峰彇start/end鐨勬墍鏈夋棩鏈熷瓧绗︿覆 鏍煎紡MM-dd
+     *
+     * @param start
+     * @param end
+     * @return
+     */
+    public static List<String> getDatesStringLists(Date start, Date end) {
+        List<String> list = new ArrayList<>();
+        int i = getDays(start, end);
+        for (int j = 0; j <= i; j++) {
+            if (j == 0) {
+                list.add(format(start, STR_MMDD));
+            } else {
+                list.add(format(plusTime(start, j), STR_MMDD));
+            }
+        }
+        return list;
+    }
+
     public static List<String> getMonthBetween(Date start, Date end) {
         List<String> list = new ArrayList<>();
         Calendar min = Calendar.getInstance();
@@ -1011,4 +1035,48 @@
         dateList.forEach(localDate -> result.add(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));
         return result;
     }
+
+    /**
+     * @param smallDate
+     * @param bigDate
+     * @desc 鑾峰彇涓や釜鏃ユ湡涔嬮棿鐨勫ぉ鏁�
+     */
+    public static Integer getDaysBetween(String smallDate, String bigDate) throws ParseException {
+        // 鏃ユ湡鏍煎紡
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+        // 鑾峰彇涓や釜鏃ユ湡鐨勬椂闂存埑
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(sdf.parse(smallDate));
+        long smallTime = cal.getTimeInMillis();
+        cal.setTime(sdf.parse(bigDate));
+        long bigTime = cal.getTimeInMillis();
+        // 鐩稿樊鐨勬棩鏈�
+        long days = (bigTime - smallTime) / (1000 * 3600 * 24);
+        // long杞琲nt 瀛樺湪婧㈠嚭鎯呭喌  鏍规嵁涓氬姟鎯呭喌缂栬緫catch涓繑鍥炲��
+        try {
+            return Integer.parseInt(String.valueOf(days));
+        } catch (NumberFormatException e) {
+            e.printStackTrace();
+            return 0;
+        }
+    }
+
+    /**
+     * 鏃ユ湡杞崲锛屽皢鎺ュ彛杩斿洖鐨�20180524杞负2018-05-24
+     *
+     * @param str
+     * @return
+     */
+    public static String dateConvertion(String str) {
+        Date parse = null;
+        String dateString = "";
+        try {
+            parse = new SimpleDateFormat("yyyyMMdd").parse(str);
+            dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse);
+        } catch (ParseException e) {
+            dateString = null;
+        }
+
+        return dateString;
+    }
 }

--
Gitblit v1.9.3