From 10f5193f23b3aae59f22fa78b0bd3277b472902e Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 27 Jul 2026 02:55:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20fetchTasks=20=E6=97=B6=E9=97=B4=E6=8C=89?= =?UTF-8?q?=20UTC=20=E8=A7=A3=E6=9E=90=E5=90=8E=E8=BD=AC=E4=B8=BA=20CST=20?= =?UTF-8?q?+08:00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/hikvision.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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'); } /**