From 6b35d07025ec6aa3b246142ee303d8ea0b84c912 Mon Sep 17 00:00:00 2001 From: wangfq Date: Wed, 10 Jun 2026 10:14:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=BE=E5=A4=87=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=A1=B5=20fmtTime=20=E4=BF=AE=E5=A4=8D=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E5=81=8F=E7=A7=BB=208=20=E5=B0=8F=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flask jsonify 把 MySQL DATETIME 序列化为 '... GMT' 但实际是本地时间。 JS new Date() 按 GMT 解析后在 UTC+8 显示会多 8 小时。 统一去除 GMT 后缀再解析(与 test_op.js 相同方案)。 --- edc-web/app/templates/device_logs.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/edc-web/app/templates/device_logs.html b/edc-web/app/templates/device_logs.html index df0c2dc..c651cf2 100644 --- a/edc-web/app/templates/device_logs.html +++ b/edc-web/app/templates/device_logs.html @@ -92,7 +92,10 @@ function eventLabel(t) { function fmtTime(v) { if (!v) return '-'; - const d = new Date(v); + // Flask jsonify 给 MySQL DATETIME 加 "GMT" 后缀,但实际值是服务器本地时间(UTC+8) + // 去掉 "GMT" 让 JS 按本地时间解析,避免时区偏移 8 小时 + const cleaned = String(v).replace(/ GMT$/, ''); + const d = new Date(cleaned); if (isNaN(d.getTime())) return String(v).substring(0, 19); const y = d.getFullYear(); const m = String(d.getMonth() + 1).padStart(2, '0');