Skip to content

Instantly share code, notes, and snippets.

@szanata
Last active January 2, 2019 17:58
Show Gist options
  • Save szanata/52655009e9a2f22c9542681d4d40f36e to your computer and use it in GitHub Desktop.
Save szanata/52655009e9a2f22c9542681d4d40f36e to your computer and use it in GitHub Desktop.
Format milliseconds to human time
const format = time => [ time, 3600000, 60000, 1000, 1 ]
.reduce( ( parts, d, i, arr ) => {
if ( i === 0 ) { return parts; }
const p = Math.floor( arr[0] / d );
arr[0] = arr[0] - (p * d);
return parts.concat( p );
}, [] ).map( t => String( t ).padStart( 2, '0' ) ).join(':');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment