21 lines
593 B
Python
21 lines
593 B
Python
|
|
"""
|
|||
|
|
时区工具
|
|||
|
|
|
|||
|
|
本系统所有时间统一使用北京时间(UTC+8)。
|
|||
|
|
边缘端上报的 event_time 是北京时间,服务端生成的时间也使用北京时间,
|
|||
|
|
确保数据库中所有时间字段语义一致。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from datetime import datetime, timezone, timedelta
|
|||
|
|
|
|||
|
|
# 北京时区 UTC+8
|
|||
|
|
BEIJING_TZ = timezone(timedelta(hours=8))
|
|||
|
|
|
|||
|
|
|
|||
|
|
def beijing_now() -> datetime:
|
|||
|
|
"""返回当前北京时间(naive datetime,无时区信息)
|
|||
|
|
|
|||
|
|
用于数据库存储,与边缘端上报的 event_time 格式一致。
|
|||
|
|
"""
|
|||
|
|
return datetime.now(BEIJING_TZ).replace(tzinfo=None)
|