1function msToTime(duration) {
2 var milliseconds = parseInt((duration % 1000) / 100),
3 seconds = Math.floor((duration / 1000) % 60),
4 minutes = Math.floor((duration / (1000 * 60)) % 60),
5 hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
6
7 hours = (hours < 10) ? "0" + hours : hours;
8 minutes = (minutes < 10) ? "0" + minutes : minutes;
9 seconds = (seconds < 10) ? "0" + seconds : seconds;
10
11 return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
12}
13console.log(msToTime(300000))
1const millisToMinutesAndSeconds = (millis) => {
2 var minutes = Math.floor(millis / 60000);
3 var seconds = ((millis % 60000) / 1000).toFixed(0);
4 //ES6 interpolated literals/template literals
5 //If seconds is less than 10 put a zero in front.
6 return `${minutes}:${(seconds < 10 ? "0" : "")}${seconds}`;
7}
8
1function msToTime(ms) {
2 let seconds = (ms / 1000).toFixed(1);
3 let minutes = (ms / (1000 * 60)).toFixed(1);
4 let hours = (ms / (1000 * 60 * 60)).toFixed(1);
5 let days = (ms / (1000 * 60 * 60 * 24)).toFixed(1);
6 if (seconds < 60) return seconds + " Sec";
7 else if (minutes < 60) return minutes + " Min";
8 else if (hours < 24) return hours + " Hrs";
9 else return days + " Days"
10}
11
12console.log(msToTime(653465))