convert milliseconds to hours minutes seconds days javascript

Solutions on MaxInterview for convert milliseconds to hours minutes seconds days javascript by the best coders in the world

showing results for - "convert milliseconds to hours minutes seconds days javascript"
Angela
11 Jan 2017
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(453543))
similar questions