js 秒转为时分秒

DL-CODER / 2023-05-16 / 原文

function formatSeconds(time) {
  const hours = Math.floor(time / 3600);
  const minutes = Math.floor((time % 3600) / 60);
  const seconds = time % 60;
  if (hours < 10) {
    return `0${hours}:0${minutes}:0${seconds}`;
  } else {
    return `${hours}:${minutes}:${seconds}`;
  }
}