stock-ai-agent/backend/app/utils/datetime_utils.py
2026-03-13 21:50:16 +08:00

28 lines
654 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.

"""
时间工具模块
提供统一的时间处理函数
"""
from datetime import datetime, timezone, timedelta
def get_beijing_time() -> datetime:
"""
获取东八区(北京时间)当前时间
Returns:
东八区的当前时间无时区信息的naive datetime
"""
utc_time = datetime.utcnow().replace(tzinfo=timezone.utc)
beijing_tz = timezone(timedelta(hours=8))
return utc_time.astimezone(beijing_tz).replace(tzinfo=None)
def get_utc_time() -> datetime:
"""
获取UTC当前时间
Returns:
UTC当前时间无时区信息的naive datetime
"""
return datetime.utcnow()