From 73a816fd2b1e29c25d615c85ce34b12b55c16ccf Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期一, 20 一月 2025 13:41:45 +0800
Subject: [PATCH] zjh20250120

---
 ltkj-common/src/main/java/com/ltkj/common/utils/DateUtils.java |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/ltkj-common/src/main/java/com/ltkj/common/utils/DateUtils.java b/ltkj-common/src/main/java/com/ltkj/common/utils/DateUtils.java
index 39e7d23..d170569 100644
--- a/ltkj-common/src/main/java/com/ltkj/common/utils/DateUtils.java
+++ b/ltkj-common/src/main/java/com/ltkj/common/utils/DateUtils.java
@@ -3,11 +3,8 @@
 import java.lang.management.ManagementFactory;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
+import java.time.*;
+import java.util.Calendar;
 import java.util.Date;
 
 import org.apache.commons.lang3.time.DateFormatUtils;
@@ -162,4 +159,52 @@
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
+    /**
+     * 鏍规嵁鏃ユ湡鑾峰彇 鏄熸湡
+     * @param
+     * @return
+     */
+    public static String dateToWeek(Date date) {
+
+        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
+        String[] weekDays = {"鏄熸湡鏃�", "鏄熸湡涓�", "鏄熸湡浜�", "鏄熸湡涓�", "鏄熸湡鍥�", "鏄熸湡浜�", "鏄熸湡鍏�"};
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        //涓�鍛ㄧ殑绗嚑澶�
+        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
+        if (w < 0)
+            w = 0;
+        return weekDays[w];
+    }
+
+    /**
+     * 鏍规嵁鐢熸棩璁$畻骞撮緞鍊间互鍙婂勾榫勫崟浣�
+     * @param birthday 鐢熸棩
+     * @return
+     */
+    public static AgeResult calculateAge(Date birthday){
+        LocalDate currentDate = LocalDate.now();
+        LocalDate birthLocalDate = birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        Period period = Period.between(birthLocalDate, currentDate);
+        if (period.getYears() > 0){
+            return new AgeResult(period.getYears(),1);
+        }
+        if (period.getMonths() > 0){
+            return new AgeResult(period.getMonths(),2);
+        }
+        LocalDateTime birthDateTime = birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
+        LocalDateTime currentDateTime = LocalDateTime.now();
+        Duration duration = Duration.between(birthDateTime, currentDateTime);
+        long days = duration.toDays();
+        if (days > 0){
+            return new AgeResult((int) days,3);
+        }
+        long hours = duration.toHours();
+        if (hours > 0){
+            return new AgeResult((int) hours,4);
+        }
+        long minutes = duration.toMinutes();
+        return new AgeResult((int) minutes,5);
+    }
 }
+

--
Gitblit v1.8.0