JavaScript秒转换成天-小时-分钟-秒

根据时间秒转换成天-小时-分钟-秒

// 秒转换成day、hour、minutes、seconds
  formatSecond(second: number) {
    const days = Math.floor(second / 86400);
    const hours = Math.floor((second % 86400) / 3600);
    const minutes = Math.floor(((second % 86400) % 3600) / 60);
    const seconds = Math.floor(((second % 86400) % 3600) % 60);
    const forMatDate = {
      days: days,
      hours: hours,
      minutes: minutes,
      seconds: seconds
    };
    return forMatDate;
  }

console.log(formatSecond(90)) // 0天0小时1分30秒
posted @ 2020-02-26 15:43  Michelyuan  阅读(4792)  评论(0编辑  收藏  举报