From 179e29d9a5ef7fe156acae846f6b43b2d1cd68c9 Mon Sep 17 00:00:00 2001 From: qiminbao Date: Sun, 28 Sep 2025 11:00:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB-=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tongran/agent/client/utils/AgentUtil.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/tongran/agent/client/utils/AgentUtil.java b/src/main/java/com/tongran/agent/client/utils/AgentUtil.java index 64dc129..eff99c2 100644 --- a/src/main/java/com/tongran/agent/client/utils/AgentUtil.java +++ b/src/main/java/com/tongran/agent/client/utils/AgentUtil.java @@ -200,15 +200,14 @@ public class AgentUtil { public static long roundMinutes(){ LocalDateTime now = LocalDateTime.now(); - // 四舍五入到最近的5分钟 - LocalDateTime roundedTime = now - .truncatedTo(ChronoUnit.MINUTES) // 先去掉秒和纳秒 - .withMinute((int) (Math.round(now.getMinute() / 5.0) * 5)) - .withSecond(0) - .withNano(0); - // 处理分钟进位的情况 - if (roundedTime.getMinute() == 60) { - roundedTime = roundedTime.plusHours(1).withMinute(0); + int minute = now.getMinute(); + int roundedMinute = (int) (Math.round(minute / 5.0) * 5); + + LocalDateTime roundedTime ; + if (roundedMinute == 60) { + roundedTime = now.plusHours(1).withMinute(0).withSecond(0).withNano(0); + } else { + roundedTime = now.withMinute(roundedMinute).withSecond(0).withNano(0); } // 转换为10位时间戳 long timestamp = roundedTime.atZone(ZoneId.systemDefault()).toEpochSecond();