From 1798d3d49d65196ae5bce840006d5ee4186f3009 Mon Sep 17 00:00:00 2001 From: zhangrenyuan <18990852002@163.com> Date: Sun, 8 Feb 2026 13:21:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=AA=E6=9D=A5?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=AF=BC=E8=87=B4=E7=9A=84=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=B7=AE=E8=AE=A1=E7=AE=97=E8=B4=9F=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当消息时间戳为未来时间时,now - msgTime 会得到负值,导致后续时间计算异常。通过将负差值强制设为0,确保时间差始终为非负数。 --- src/utils/getMessage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/getMessage.js b/src/utils/getMessage.js index 576d845..839a85c 100644 --- a/src/utils/getMessage.js +++ b/src/utils/getMessage.js @@ -15,7 +15,10 @@ function formatTime(timeStr) { // 函数逻辑不变... const now = new Date(); const msgTime = new Date(timeStr); - const diffMs = now - msgTime; + let diffMs = now - msgTime; + if (diffMs < 0) { + diffMs = 0 + } const diffMins = Math.floor(diffMs / (1000 * 60)); const diffHours = Math.floor(diffMins / 60); const diffDays = Math.floor(diffHours / 24);