Skip to content

Instantly share code, notes, and snippets.

@timhughes
Created October 31, 2024 23:55
Show Gist options
  • Save timhughes/3b88cd34f4f868dc57892e1d6af9b7ec to your computer and use it in GitHub Desktop.
Save timhughes/3b88cd34f4f868dc57892e1d6af9b7ec to your computer and use it in GitHub Desktop.
[javascript] Convert seconds to a human readable format
const sec= 3333
function convert_seconds(sec) {
const divmod = (x, y) => [Math.floor(x / y), x % y];
var d,h,m,s;
var [m, s] = divmod(sec, 60);
var [h, m] = divmod(m, 60);
var [d, h] = divmod(h, 24);
return `${d}d,${h}h,${m}m,${s}s`;
}
console.log(convert_seconds(sec))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment