From 73372f312e8b8bae98623006640b016f9a433988 Mon Sep 17 00:00:00 2001
From: nickchange <126672920+nickchange@users.noreply.github.com>
Date: 星期一, 16 十月 2023 15:12:49 +0800
Subject: [PATCH] 10.16
---
cloud-server-account/src/main/java/com/dsh/account/util/DateTimeHelper.java | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/cloud-server-account/src/main/java/com/dsh/account/util/DateTimeHelper.java b/cloud-server-account/src/main/java/com/dsh/account/util/DateTimeHelper.java
index 32dffb1..2d7b310 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/util/DateTimeHelper.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/util/DateTimeHelper.java
@@ -2,9 +2,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
+import java.time.*;
import java.util.*;
@@ -1350,6 +1348,20 @@
}
/**
+ * 获取指定月份开始时0点0分0秒
+ * @param input 输入的时间,"yyyy-MM"
+ * @return
+ */
+ public static Date getCurrentIdetMouthStart(String input) {
+ // 解析年月字符串
+ YearMonth yearMonth = YearMonth.parse(input);
+ // 获取月份的开始时间(月初0点)
+ LocalDate startOfMonth = yearMonth.atDay(1);
+ LocalDateTime startDateTime = startOfMonth.atTime(LocalTime.MIN);
+ return Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ /**
* 获取当月结束时23点59分59秒
*
* @return
@@ -1364,6 +1376,21 @@
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
+ }
+
+
+ /**
+ * 获取指定月份结束时23点59分59秒
+ * @param input 输入的时间,"yyyy-MM"
+ * @return
+ */
+ public static Date getCurrentIdeaMouthEnd(String input) {
+ // 解析年月字符串
+ YearMonth yearMonth = YearMonth.parse(input);
+ // 获取月份的结束时间(月末23:59:59秒)
+ LocalDate endOfMonth = yearMonth.atEndOfMonth();
+ LocalDateTime endDateTime = endOfMonth.atTime(23, 59, 59);
+ return Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
/**
@@ -1457,6 +1484,23 @@
}
/**
+ * 获取当前日期是星期几<br>
+ * Obtain the day of the week for the current date.
+ * @param dt
+ * @return 当前日期是星期几
+ */
+ public static int getWeekNumOfDate(Date dt) {
+ Integer[] weekDays = {7, 1, 2, 3, 4, 5, 6}; // 将周一的数值设为2,依次递增表示周二到周日
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(dt);
+ int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
+ if (w < 0) {
+ w = 6; // 如果为负数,将其设为6,表示周日
+ }
+ return weekDays[w];
+ }
+
+ /**
* 获取今天时间 2017-11-20 00:00:00
*/
public static Date todayDate() {
--
Gitblit v1.7.1