fix: 修复前端时间显示问题,正确处理UTC时间并转换为本地时间(北京时间)
- 修改 formatDate 函数,识别 SQLite 返回的 UTC 时间格式 - 自动将 UTC 时间字符串转换为 ISO 格式并添加 'Z' 标记 - JavaScript Date 对象会自动将 UTC 时间转换为本地时间显示 - 修复之前显示 13号(UTC) 而不是 14号(CST) 的问题
This commit is contained in:
@@ -1735,7 +1735,16 @@ handleDragLeave(e) {
|
||||
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return '-';
|
||||
const date = new Date(dateString);
|
||||
|
||||
// SQLite 返回的是 UTC 时间字符串,需要显式处理
|
||||
// 如果字符串不包含时区信息,手动添加 'Z' 标记为 UTC
|
||||
let dateStr = dateString;
|
||||
if (!dateStr.includes('Z') && !dateStr.includes('+') && !dateStr.includes('T')) {
|
||||
// SQLite 格式: "2025-11-13 16:37:19" -> ISO格式: "2025-11-13T16:37:19Z"
|
||||
dateStr = dateStr.replace(' ', 'T') + 'Z';
|
||||
}
|
||||
|
||||
const date = new Date(dateStr);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
|
||||
Reference in New Issue
Block a user