|
|
|
@ -2,10 +2,7 @@ package com.dongjian.dashboard.back.util; |
|
|
|
|
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.DayOfWeek; |
|
|
|
import java.time.Instant; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.*; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.temporal.IsoFields; |
|
|
|
import java.util.*; |
|
|
|
@ -95,4 +92,29 @@ public class DateUtil { |
|
|
|
.minusDays(1); |
|
|
|
return japanYesterday.format(FORMATTER); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据前端传来的时区偏移(分钟),获取该时区当天 0 点的毫秒时间戳 |
|
|
|
* @param offsetMinutes 前端传递的偏移量,例如东八区为 -480 |
|
|
|
* @return 当天 0 点的毫秒级时间戳(UTC) |
|
|
|
*/ |
|
|
|
public static long getTodayZeroMillisByOffset(Integer offsetMinutes) { |
|
|
|
// 若未传偏移,可使用默认时区(如系统默认或东八区)
|
|
|
|
if (offsetMinutes == null) { |
|
|
|
// 默认日本时区(+9)
|
|
|
|
offsetMinutes = -540; |
|
|
|
} |
|
|
|
|
|
|
|
// 将前端 offset 转换为 ZoneOffset(例如 -480 -> +08:00)
|
|
|
|
int offsetSeconds = -offsetMinutes * 60; // 注意负负得正
|
|
|
|
ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(offsetSeconds); |
|
|
|
|
|
|
|
// 当前时刻在该偏移下的当天0点
|
|
|
|
ZonedDateTime todayZero = ZonedDateTime.now(zoneOffset) |
|
|
|
.toLocalDate() |
|
|
|
.atStartOfDay(zoneOffset); |
|
|
|
|
|
|
|
// 返回毫秒时间戳
|
|
|
|
return todayZero.toInstant().toEpochMilli(); |
|
|
|
} |
|
|
|
} |
|
|
|
|