2020-04-04 04:23:29 +00:00
|
|
|
module.exports = function msToTime(duration, format) {
|
|
|
|
var seconds = Math.floor((duration / 1000) % 60),
|
|
|
|
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
2020-08-22 17:48:22 +00:00
|
|
|
hours = Math.floor((duration / (1000 * 60 * 60)) % 24),
|
2020-08-22 17:19:38 +00:00
|
|
|
days = Math.floor((duration / (1000 * 60 * 60 * 24)));
|
2020-04-04 04:23:29 +00:00
|
|
|
|
|
|
|
days = (days < 10) ? "0" + days : days;
|
|
|
|
hours = (hours < 10) ? "0" + hours : hours;
|
|
|
|
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
|
|
|
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
|
|
|
|
|
|
|
if (format === "hh:mm:ss") {
|
|
|
|
return `${hours}:${minutes}:${seconds}`;
|
|
|
|
} else if (format === "dd:hh:mm:ss") {
|
|
|
|
return `${days}:${hours}:${minutes}:${seconds}`;
|
|
|
|
}
|
2020-04-02 05:13:51 +00:00
|
|
|
}
|