fix: fetchTasks 时间按 UTC 解析后转为 CST +08:00
This commit is contained in:
parent
8dbc238acf
commit
10f5193f23
@ -9,15 +9,17 @@ const BaseService = require('./base');
|
|||||||
*/
|
*/
|
||||||
class HikvisionService extends BaseService {
|
class HikvisionService extends BaseService {
|
||||||
/**
|
/**
|
||||||
* 将 MySQL DATETIME 字符串转为 ISO 8601 带时区偏移 (+08:00)
|
* 将 MySQL DATETIME(存储为 UTC)转为 ISO 8601 北京时间 (+08:00)
|
||||||
* 输入: "2026-07-26 11:08:48" → 输出: "2026-07-26T11:08:48+08:00"
|
* DB 存: "2026-07-26 11:08:19" (UTC) → 输出: "2026-07-26T19:08:19+08:00"
|
||||||
*/
|
*/
|
||||||
_toISO(datetime) {
|
_toISO(datetime) {
|
||||||
if (!datetime) return null;
|
if (!datetime) return null;
|
||||||
const str = String(datetime).trim();
|
const str = String(datetime).trim();
|
||||||
// 如果已经是 ISO 格式就不要再转
|
// 按 UTC 解析
|
||||||
if (str.includes('T')) return str.replace('Z', '+08:00');
|
const utc = new Date(str + 'Z');
|
||||||
return str.replace(' ', 'T') + '+08:00';
|
// 转为北京时间
|
||||||
|
const cst = new Date(utc.getTime() + 8 * 3600000);
|
||||||
|
return cst.toISOString().replace('Z', '+08:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user