File size: 721 Bytes
a1ff683 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from __future__ import annotations
from datetime import datetime, timedelta, timezone
try:
from zoneinfo import ZoneInfo
except ImportError: # pragma: no cover
ZoneInfo = None # type: ignore[assignment]
CHINA_TZ = ZoneInfo("Asia/Shanghai") if ZoneInfo else timezone(timedelta(hours=8))
def china_now() -> datetime:
return datetime.now(CHINA_TZ)
def china_now_string() -> str:
return china_now().strftime("%Y-%m-%d %H:%M:%S")
def china_from_timestamp_string(value: float) -> str:
return datetime.fromtimestamp(value, CHINA_TZ).strftime("%Y-%m-%d %H:%M:%S")
def china_date_from_timestamp_string(value: float) -> str:
return datetime.fromtimestamp(value, CHINA_TZ).strftime("%Y-%m-%d")
|