#977 时间错位8小时彻底修复 - _beijing_now返回aware
CI / gate (push) Has been cancelled

根因: _beijing_now返回naive datetime(无时区), PG timestamptz列按UTC误解, 存13:53UTC前端按Asia/Shanghai显示21:53错位8小时。修复: 去掉replace(tzinfo=None)返回aware datetime(带+08:00), PG正确转UTC存储, 前端正确显示。
This commit is contained in:
qihu-bot committed 2026-08-18 14:01:57 +08:00
1 parent ab11283d92
commit 552a962123
2 files changed
+9 -4

No files matched your search

+2 -2
View File
@@ -21,8 +21,8 @@ _TZ_BEIJING = timezone(timedelta(hours=8))
def _beijing_now():
"""返回 naive 北京时间(容器 UTC 时区下,需显式转)"""
return datetime.now(_TZ_BEIJING).replace(tzinfo=None)
"""返回带时区的北京时间(aware datetime,存 PG timestamptz 不误解)。"""
return datetime.now(_TZ_BEIJING)
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Query