quark-auto-save/app/sdk/common.py
xiaoQQya 1fad4d7137
Some checks failed
Docker Publish / build-and-push (push) Has been cancelled
🐛 修复资源时间格式解析错误导致搜索失败的问题 (#115)
* fix: 修复资源时间格式解析错误导致搜索失败的问题
* feat: 资源搜索结果显示来源通道
2025-08-23 16:26:11 +08:00

16 lines
539 B
Python

from datetime import datetime, timezone, timedelta
def iso_to_cst(iso_time_str: str) -> str:
"""将 ISO 格式的时间字符串转换为 CST(China Standard Time) 时间并格式化为 %Y-%m-%d %H:%M:%S 格式
Args:
iso_time_str (str): ISO 格式时间字符串
Returns:
str: CST(China Standard Time) 时间字符串
"""
dt = datetime.fromisoformat(iso_time_str)
dt_cst = dt.astimezone(timezone(timedelta(hours=8)))
return dt_cst.strftime("%Y-%m-%d %H:%M:%S") if dt_cst.year >= 1970 else ""