huoyan-enterprise/backend/utils/datetime_utils.py

26 lines
731 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.

"""
北京时间等时间工具(供 Agent 工具、提示词等复用)。
使用 IANA 时区 Asia/Shanghai与 UTC+8 一致,并正确处理夏令时历史等边界情况(中国无夏令时)。
"""
from __future__ import annotations
from datetime import datetime
from zoneinfo import ZoneInfo
BEIJING_TZ = ZoneInfo("Asia/Shanghai")
def get_beijing_now() -> datetime:
"""当前北京时间Asia/Shanghai"""
return datetime.now(BEIJING_TZ)
def format_beijing_time_for_agent() -> str:
"""
供「当前时间」工具返回的固定格式文案。
"""
dt = get_beijing_now()
return (
f"📅 当前时间:{dt.strftime('%Y年%m月%d%H:%M:%S')} (北京时间)\n\n"
)