From a30f3b966f6b3c1748d2976364369596327cbfba Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期一, 21 八月 2023 17:40:04 +0800
Subject: [PATCH] 后台代码 积分商品
---
cloud-server-account/src/main/java/com/dsh/account/util/LocalDateTimeUtils.java | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/cloud-server-account/src/main/java/com/dsh/account/util/LocalDateTimeUtils.java b/cloud-server-account/src/main/java/com/dsh/account/util/LocalDateTimeUtils.java
index 87835a6..08fc7c1 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/util/LocalDateTimeUtils.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/util/LocalDateTimeUtils.java
@@ -1,9 +1,11 @@
package com.dsh.account.util;
import java.text.ParseException;
+import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
/**
* LocalDateTimeUtils
@@ -77,4 +79,31 @@
Integer day=date.getDayOfMonth();
return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month];
}
+
+ /**
+ * 获取当天的星期几
+ * @return
+ */
+ public static int getWeekStr(){
+ LocalDate today = LocalDate.now();
+ DayOfWeek dayOfWeek = today.getDayOfWeek();
+ return dayOfWeek.getValue();
+ }
+
+ public static String getWeekOfDays(int desiredDayOfWeek){
+ // 获取当前日期
+ LocalDate currentDate = LocalDate.now();
+
+ // 获取当前周的第一天(默认以星期一为一周的开始)
+ LocalDate firstDayOfWeek = currentDate.with(DayOfWeek.MONDAY);
+
+ LocalDate desiredDate = firstDayOfWeek.plusDays(desiredDayOfWeek - 1);
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd");
+ return desiredDate.format(formatter);
+ }
+//
+// public static void main(String[] args) {
+// String weekOfDays = LocalDateTimeUtils.getWeekOfDays(4);
+// System.out.println(weekOfDays);
+// }
}
--
Gitblit v1.7.1