时间显示异常

This commit is contained in:
YueL1331
2026-01-14 14:42:33 +08:00
parent 9ebfd79414
commit f043983d24
4 changed files with 137 additions and 48 deletions

View File

@ -258,6 +258,25 @@ def devices_overview():
for d in devices:
item = d.to_dict()
# =========== 【新增修复】强制格式化时间 ===========
# 无论模型返回什么,这里都强制从数据库原始字段获取,并确保包含时分秒
raw_time = d.latest_time
if raw_time:
# 1. 如果是 datetime 对象 (防万一)
if hasattr(raw_time, 'strftime'):
item['latest_time'] = raw_time.strftime("%Y-%m-%d %H:%M:%S")
# 2. 如果是字符串
else:
s = str(raw_time).strip()
# 如果只有日期且用下划线 (如 2026_01_14),且没有冒号,则补全
if '_' in s and ':' not in s:
item['latest_time'] = s.replace('_', '-') + " 00:00:00"
else:
# 已经是正常字符串(如 2026-01-14 13:49:26直接使用
item['latest_time'] = s
# ===============================================
parsed_content = {}
if d.json_data:
try: