diff --git a/app/service/hikvision.js b/app/service/hikvision.js index ed6ceae..84b7995 100644 --- a/app/service/hikvision.js +++ b/app/service/hikvision.js @@ -9,15 +9,17 @@ const BaseService = require('./base'); */ class HikvisionService extends BaseService { /** - * 将 MySQL DATETIME 字符串转为 ISO 8601 带时区偏移 (+08:00) - * 输入: "2026-07-26 11:08:48" → 输出: "2026-07-26T11:08:48+08:00" + * 将 MySQL DATETIME(存储为 UTC)转为 ISO 8601 北京时间 (+08:00) + * DB 存: "2026-07-26 11:08:19" (UTC) → 输出: "2026-07-26T19:08:19+08:00" */ _toISO(datetime) { if (!datetime) return null; const str = String(datetime).trim(); - // 如果已经是 ISO 格式就不要再转 - if (str.includes('T')) return str.replace('Z', '+08:00'); - return str.replace(' ', 'T') + '+08:00'; + // 按 UTC 解析 + const utc = new Date(str + 'Z'); + // 转为北京时间 + const cst = new Date(utc.getTime() + 8 * 3600000); + return cst.toISOString().replace('Z', '+08:00'); } /**