Skip to content

Instantly share code, notes, and snippets.

@timhughes
Created October 31, 2024 23:55
Show Gist options
  • Select an option

  • Save timhughes/3b88cd34f4f868dc57892e1d6af9b7ec to your computer and use it in GitHub Desktop.

Select an option

Save timhughes/3b88cd34f4f868dc57892e1d6af9b7ec to your computer and use it in GitHub Desktop.

Revisions

  1. timhughes created this gist Oct 31, 2024.
    11 changes: 11 additions & 0 deletions convert_seconds.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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))