时间戳毫秒转换为以天为单位的时间格式:
直接放代码
function formatTimeSpan(ms: number) { if (!ms) return "0秒"; if (ms < 1000) return "<1秒"; let sec_a = Math.round(ms / 1000); let min_a = Math.floor(sec_a / 60); let sec = sec_a - min_a * 60; let hour_a = Math.floor(min_a / 60); let min = min_a - hour_a * 60; let d = Math.floor(hour_a / 24); let hour = hour_a - d * 24; let str = ""; if (sec) str = sec + "秒" + str; if (!min_a) return str; if (min) str = min + "分钟" + str; if (!hour_a) return str; if (hour) str = hour + "小时" + str; if (!d) return str; return d + "天" + str; }