From 125924f74e3cb309e4a49de304a09e5edc8d75b6 Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期二, 28 五月 2024 18:25:21 +0800
Subject: [PATCH] ''
---
server/system_service/src/main/java/com/doumee/core/utils/DateUtil.java | 79 ++++++++++++++++++++++++++++++++++-----
1 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/server/system_service/src/main/java/com/doumee/core/utils/DateUtil.java b/server/system_service/src/main/java/com/doumee/core/utils/DateUtil.java
index 2ccb323..e76940e 100644
--- a/server/system_service/src/main/java/com/doumee/core/utils/DateUtil.java
+++ b/server/system_service/src/main/java/com/doumee/core/utils/DateUtil.java
@@ -7,10 +7,13 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.Date;
+import cn.hutool.core.date.DateUnit;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -1876,11 +1879,10 @@
}
public static int compareDate(String format, String str1, Date date2) {
-
Date date1 = null;
try {
date1 = fromStringToDate(format, str1);
- } catch (ParseException e) {
+ } catch (Exception e) {
// TODO 鑷姩鐢熸垚 catch 鍧�
e.printStackTrace();
}
@@ -2403,6 +2405,16 @@
return new Timestamp(System.currentTimeMillis());
}
}
+ public static Date getDateFromString2(String strDate) {
+ if (StringUtils.isEmpty(strDate)) {
+ return null;
+ }
+ try {
+ return sdfLongTimePlus.parse(strDate);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
// -----------------------------------------------------------------------
@@ -2785,7 +2797,7 @@
stringDate = getFomartDate(new Date(now), formate);
- } catch (ParseException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
@@ -2800,8 +2812,7 @@
long now = date.getTime() + (long) Integer.parseInt(days) * DAY_IN_MILLISECOND;
date = new Date(now);
-
- } catch (ParseException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
@@ -2818,10 +2829,16 @@
*
* 瀛楃涓插舰寮忚浆鍖栦负Date绫诲瀷 String绫诲瀷鎸夌収format鏍煎紡杞负Date绫诲瀷
**/
- public static Date fromStringToDate(String format, String dateTime) throws ParseException {
+ public static Date fromStringToDate(String format, String dateTime) {
Date date = null;
- SimpleDateFormat sdf = new SimpleDateFormat(format);
- date = sdf.parse(dateTime);
+ try {
+
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
+ date = sdf.parse(dateTime);
+ }catch (Exception e){
+
+ }
+
return date;
}
@@ -2835,9 +2852,21 @@
public static void main(String[] args) {
try {
- Date date = getISO8601DateByStr("2024-04-15T07:46:36.014+08:00");
- Date date1 = getISO8601DateByStr("2024-06-14T08:46:36.014+08:00");
- System.out.println(daysBetweenDates11(date1,date)+1);
+// Date date = getISO8601DateByStr("2024-04-15T07:46:36.014+08:00");
+// Date date1 = getISO8601DateByStr("2024-06-14T08:46:36.014+08:00");
+// System.out.println(DateUtil.afterMinutesDate(-5));
+
+
+ Date startTime = DateUtil.StringToDate("2024-05-01 08:00:00" ,"yyyy-MM-dd HH:mm:ss");
+ Date endTime = DateUtil.StringToDate("2024-05-01 17:00:00" ,"yyyy-MM-dd HH:mm:ss");
+ Long intervalTime = 35L;
+
+
+ DateUtil.checkDateInterval( startTime.toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDateTime(), endTime.toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDateTime(),intervalTime);
} catch (Exception ex) {
ex.printStackTrace();
@@ -3094,6 +3123,18 @@
}
/**
+ * X 鍒嗛挓鍚庢椂闂�
+ * @param minutes
+ * @return
+ */
+ public static Date afterMinutesDate(Date date,Integer minutes){
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.add(Calendar.MINUTE,minutes);
+ return cal.getTime();
+ }
+
+ /**
* LocalDateTime to date
* @param now
* @return
@@ -3238,4 +3279,20 @@
System.out.println(time);
return time;
}
+
+
+
+ public static List<LocalDateTime> checkDateInterval(LocalDateTime localStartTime,LocalDateTime localEndTime,Long interval){
+ List<LocalDateTime> segments = new ArrayList<>();
+ LocalDateTime current = localStartTime;
+ while (current.isBefore(localEndTime)) {
+ segments.add(current);
+ current = current.plus(interval, ChronoUnit.MINUTES);
+ }
+ return segments;
+
+ }
+
+
+
}
\ No newline at end of file
--
Gitblit v1.9.3