Last active
January 2, 2019 17:58
-
-
Save szanata/52655009e9a2f22c9542681d4d40f36e to your computer and use it in GitHub Desktop.
Format milliseconds to human time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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