From ab3b38203201983915b5a7ae0c871b8709872cda Mon Sep 17 00:00:00 2001 From: fengyarnom Date: Thu, 15 May 2025 16:41:20 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=98=BE=E7=A4=BA=E6=97=B6=E9=97=B4=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/index.html | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/static/index.html b/static/index.html index 4c37c54..feb5558 100644 --- a/static/index.html +++ b/static/index.html @@ -213,13 +213,17 @@ } const labels = data.map(item => { - const date = new Date(item.timestamp); + // 确保使用正确的时间格式解析 + const date = new Date(item.timestamp.replace(' ', 'T') + 'Z'); + // 调整为本地时间 + const localDate = new Date(date.getTime() + (8 * 60 * 60 * 1000)); + // 格式化为中文日期时间格式 - return date.getFullYear() + '/' + - (date.getMonth() + 1).toString().padStart(2, '0') + '/' + - date.getDate().toString().padStart(2, '0') + ' ' + - date.getHours().toString().padStart(2, '0') + ':' + - date.getMinutes().toString().padStart(2, '0'); + return localDate.getFullYear() + '/' + + (localDate.getMonth() + 1).toString().padStart(2, '0') + '/' + + localDate.getDate().toString().padStart(2, '0') + ' ' + + localDate.getHours().toString().padStart(2, '0') + ':' + + localDate.getMinutes().toString().padStart(2, '0'); }); mainChart = new Chart(ctx, { @@ -284,16 +288,18 @@ data.forEach(item => { const row = document.createElement('tr'); - const date = new Date(item.timestamp); + // 确保使用正确的时间格式解析 + const date = new Date(item.timestamp.replace(' ', 'T') + 'Z'); + // 调整为本地时间 + const localDate = new Date(date.getTime() + (8 * 60 * 60 * 1000)); - // 格式化为中文日期时间格式 const formattedDate = - date.getFullYear() + '/' + - (date.getMonth() + 1).toString().padStart(2, '0') + '/' + - date.getDate().toString().padStart(2, '0') + ' ' + - date.getHours().toString().padStart(2, '0') + ':' + - date.getMinutes().toString().padStart(2, '0') + ':' + - date.getSeconds().toString().padStart(2, '0'); + localDate.getFullYear() + '/' + + (localDate.getMonth() + 1).toString().padStart(2, '0') + '/' + + localDate.getDate().toString().padStart(2, '0') + ' ' + + localDate.getHours().toString().padStart(2, '0') + ':' + + localDate.getMinutes().toString().padStart(2, '0') + ':' + + localDate.getSeconds().toString().padStart(2, '0'); row.innerHTML = ` ${formattedDate}