turn seconds to day, hour, min in javascript

To convert seconds to the day , hour , and minute format, you can use the following function in JavaScript:

index.tsx
function secondsToDHM(seconds) {
  seconds = Number(seconds);
  var d = Math.floor(seconds / (3600*24));
  var h = Math.floor(seconds % (3600*24) / 3600);
  var m = Math.floor(seconds % 3600 / 60);
  return d + " day(s) " + h + " hour(s) " + m + " minute(s)";
}
262 chars
8 lines

This function takes the input of seconds and returns the output in the format of the number of days, hours and minutes. For example, if you input 100000 seconds, it returns "1 day(s) 4 hour(s) 26 minute(s)".

You can call this function with the required seconds as input, like this:

index.tsx
console.log(secondsToDHM(100000)); // 1 day(s) 4 hour(s) 26 minute(s)
70 chars
2 lines

gistlibby LogSnag