From 14c03b65ebfc62d32bcfeff2c1b4338247b50729 Mon Sep 17 00:00:00 2001
From: whycxzp <glperry@163.com>
Date: 星期五, 13 六月 2025 16:54:51 +0800
Subject: [PATCH] 蓄电池核容测试信息统计

---
 src/main/java/com/whyc/util/DateUtil.java |   64 ++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/src/main/java/com/whyc/util/DateUtil.java b/src/main/java/com/whyc/util/DateUtil.java
index 7421971..2e9a81d 100644
--- a/src/main/java/com/whyc/util/DateUtil.java
+++ b/src/main/java/com/whyc/util/DateUtil.java
@@ -2,6 +2,10 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 
 /**
@@ -704,33 +708,39 @@
     }
 
 
-    public static void main(String[] args) throws ParseException {
-        //Date d1 = YYYY_MM_DD_HH_MM_SS.parse("2023-01-22 14:12:22");
-        //Date d2 = YYYY_MM_DD_HH_MM_SS.parse("2023-08-24 16:45:22");
-        //Map<String, List<Date>> monthListDesc = getQueryTimeForSubTablesByMonthDesc(d1, d2);
-        //
-        //Set<Map.Entry<String, List<Date>>> entries = monthListDesc.entrySet();
-        //for (Map.Entry<String, List<Date>> entry : entries) {
-        //    System.out.println(entry);
-        //}
-        //Map<String,String> map = new HashMap<>();
-        //map.put("2022_01","");
-        //map.put("2022_02","");
-        //map.put("2022_10","");
-        //map.put("2022_12","");
-        //map.put("2021_03","");
-        //map.put("2023_01","");
-        //map.put("2023_05","");
-        //map.put("2021_10","");
-        //Set<String> keySet = map.keySet();
-        //List<String> keySetDesc = keySet.stream().sorted(Comparator.comparing(String::hashCode).reversed()).collect(Collectors.toList());
-        String t1 = "2024-01-25 12:22:29";
-        String t2 = "2024-01-25 12:32:24";
-        String t3 = "2024-01-25 12:42:26";
-        Date maxTime = getMaxTime(t1, t2, t3);
-        System.out.println(maxTime.toString());
-
-
+    /**
+     * 鑾峰彇鏈勾鐨勫紑濮嬫椂闂�
+     */
+    public static LocalDateTime getStartOfYear() {
+        LocalDateTime now = LocalDateTime.now();
+        return now.with(TemporalAdjusters.firstDayOfYear()).with(LocalDateTime.MIN.toLocalTime());
     }
 
+    /**
+     * 鑾峰彇鏈搴︾殑寮�濮嬫椂闂�
+     */
+    public static LocalDateTime getStartOfQuarter() {
+        LocalDateTime now = LocalDateTime.now();
+        int currentMonthValue = now.getMonthValue();
+        // 璁$畻褰撳墠瀛e害鐨勭涓�涓湀
+        int quarterStartMonth = 3 * ((currentMonthValue - 1) / 3) + 1;
+        return LocalDate.of(now.getYear(), quarterStartMonth, 1).atStartOfDay();
+    }
+
+    /**
+     * 鑾峰彇鏈湀鐨勫紑濮嬫椂闂�
+     */
+    public static LocalDateTime getStartOfMonth() {
+        LocalDateTime now = LocalDateTime.now();
+        return now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalDateTime.MIN.toLocalTime());
+    }
+
+    /**
+     * Date 杞� LocalDateTime 宸ュ叿鏂规硶
+     */
+    public static LocalDateTime convertToLocalDateTime(java.util.Date date) {
+        return date.toInstant()
+                .atZone(ZoneId.systemDefault())
+                .toLocalDateTime();
+    }
 }

--
Gitblit v1.9.1