From e2ba9233702c4e0f73a58e2d51e2a9ca0a77792e Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Sat, 30 Aug 2025 22:11:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B5=84=E6=BA=90=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=BB=93=E6=9E=9C=E5=8F=91=E5=B8=83=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=97=B6=E5=8C=BA=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在前端 formatPublishDate 函数中添加时区修复逻辑 - 智能识别 UTC 时间(包含 T 或 Z)并自动 +8 小时转换为北京时间 - 保持标准北京时间格式不变 - 解决发布时间显示提早 8 小时的问题 --- app/templates/index.html | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/templates/index.html b/app/templates/index.html index 55e7c94..3e8fef1 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -6628,18 +6628,52 @@ formatPublishDate(value) { if (!value) return ''; const s = String(value).trim(); + // 已是标准格式则直接返回 if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(s)) return s; + // 优先匹配 ISO 主体部分 const m = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})/.exec(s); if (m) { const [, y, mo, d, h, mi, se] = m; + // 修复时区问题:如果时间以Z结尾或包含T,说明是UTC时间,需要+8小时 + if (s.includes('T') || s.includes('Z')) { + // 创建Date对象并加上8小时 + const date = new Date(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(se)); + date.setHours(date.getHours() + 8); + return date.getFullYear() + '-' + + String(date.getMonth() + 1).padStart(2, '0') + '-' + + String(date.getDate()).padStart(2, '0') + ' ' + + String(date.getHours()).padStart(2, '0') + ':' + + String(date.getMinutes()).padStart(2, '0') + ':' + + String(date.getSeconds()).padStart(2, '0'); + } return `${y}-${mo}-${d} ${h}:${mi}:${se}`; } + // 回退:简单替换T为空格并去除尾部Z/时区偏移 let out = s.replace('T', ' '); out = out.replace(/Z$/i, ''); out = out.replace(/([+-]\d{2}:?\d{2})$/i, ''); + + // 如果原始时间包含T或Z,说明是UTC时间,需要+8小时 + if (s.includes('T') || s.includes('Z')) { + try { + const date = new Date(out); + if (!isNaN(date.getTime())) { + date.setHours(date.getHours() + 8); + return date.getFullYear() + '-' + + String(date.getMonth() + 1).padStart(2, '0') + '-' + + String(date.getDate()).padStart(2, '0') + ' ' + + String(date.getHours()).padStart(2, '0') + ':' + + String(date.getMinutes()).padStart(2, '0') + ':' + + String(date.getSeconds()).padStart(2, '0'); + } + } catch (e) { + // 如果转换失败,返回原始处理结果 + } + } + return out; }, changeFolderPage(page) {