s3-time-format.md 773 Bytes

S3: 消息发送时间显示(当日 HH:mm,跨日 MM-dd HH:mm)

目标

修改 chat.html 的 renderMsg() 函数,让时间显示根据日期智能切换格式。

涉及文件

  • templates/chat.html:renderMsg() 中时间格式化逻辑

当前行为

const timeStr = time.toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'});
// 所有消息都只显示 HH:mm,不区分当天/非当天

期望行为

  • 当天消息:HH:mm(如 14:30)
  • 非当天消息:MM-dd HH:mm(如 07-10 14:30)

步骤

  1. 在 renderMsg() 中获取今天的日期
  2. 比较消息日期和今天日期
  3. 同一天:HH:mm
  4. 不同天:MM-dd HH:mm

验证

  • curl 聊天页 → 检查 JS 中有 getDate() 或日期比较逻辑
  • smoketest 8/8