Created
March 31, 2019 12:05
-
-
Save NuarkNoir/92dbb6ca3ced600277a32fd50aa121d0 to your computer and use it in GitHub Desktop.
Fancy time formater
This file contains hidden or 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
let fancyTimeFormat = function (time) { | |
// Hours, minutes and seconds | |
var hrs = ~~(time / 3600); | |
var mins = ~~((time % 3600) / 60); | |
var secs = ~~time % 60; | |
// Output like "1:01" or "4:03:59" or "123:03:59" | |
var ret = ""; | |
if (hrs > 0) { | |
ret += "" + hrs + ":" + (mins < 10 ? "0" : ""); | |
} | |
ret += "" + mins + ":" + (secs < 10 ? "0" : ""); | |
ret += "" + secs; | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment