PMFlow/backend/app/utils/timezone.py

19 lines
501 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""PMFlow 时间工具:统一使用北京时间(Asia/Shanghai)。"""
from __future__ import annotations
from datetime import datetime, timedelta, timezone
CN_TZ = timezone(timedelta(hours=8), name="Asia/Shanghai")
def now_cn_aware() -> datetime:
"""返回带时区的北京时间。"""
return datetime.now(CN_TZ)
def now_cn_naive() -> datetime:
"""返回不带时区的北京时间(用于 TIMESTAMP WITHOUT TIME ZONE)。"""
return now_cn_aware().replace(tzinfo=None)