根因: _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:
1 parent
ab11283d92
commit
552a962123
2 files changed
+9
-4
No files matched your search
@@ -40,8 +40,13 @@ TZ_BEIJING = timezone(timedelta(hours=8))
|
||||
|
||||
|
||||
def _beijing_now() -> datetime:
|
||||
"""返回北京时间的 naive datetime(去掉 tzinfo 以便直接存入 MySQL DATETIME)。"""
|
||||
return datetime.now(TZ_BEIJING).replace(tzinfo=None)
|
||||
"""返回带时区的北京时间(aware datetime)。
|
||||
|
||||
#977 关键修复:平台已全量迁 PG(时间列均为 timestamp with time zone),
|
||||
必须返回 aware datetime。此前 .replace(tzinfo=None) 返回 naive,PG 按 UTC
|
||||
误解导致错位 8 小时(如北京时间 13:53 存成 13:53 UTC → 前端显示 21:53)。
|
||||
"""
|
||||
return datetime.now(TZ_BEIJING)
|
||||
|
||||
# ============================================================
|
||||
# iLink 协议常量(腾讯官方 iLink Bot HTTP API,直连免 AppID)
|
||||
|
||||
Reference in new issue
Block a user