diff --git a/ethend/src/index.js b/ethend/src/index.js index 8d05f03..69569c7 100644 --- a/ethend/src/index.js +++ b/ethend/src/index.js @@ -1907,12 +1907,19 @@ server.listen(ETHEND_PORT, () => { } }); -// 时间格式化:UTC+8 本地时间 +// 时间格式化:始终显示 UTC+8 (Asia/Shanghai) function formatLocalTime(ts) { var d = new Date(ts); var pad = function(n) { return n < 10 ? '0' + n : '' + n; }; - return d.getFullYear() + '-' + pad(d.getMonth()+1) + '-' + pad(d.getDate()) + ' ' + - pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds()); + // Force UTC+8 regardless of system timezone + var utcH = d.getUTCHours(); + var utcM = d.getUTCMinutes(); + var utcS = d.getUTCSeconds(); + var localH = (utcH + 8) % 24; + var dayOffset = Math.floor((utcH + 8) / 24); + var localD = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + dayOffset)); + return localD.getUTCFullYear() + '-' + pad(localD.getUTCMonth()+1) + '-' + pad(localD.getUTCDate()) + ' ' + + pad(localH) + ':' + pad(utcM) + ':' + pad(utcS); } // 优雅退出