Last active
April 16, 2020 14:02
-
-
Save robpataki/d0b40a1cbbb71764dd94e16cbc99d42f to your computer and use it in GitHub Desktop.
Convert time in milliseconds to human readable hours:minutes:seconds formatedt string
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
var getTimeString = function(timeInMs) { | |
var delim = ":"; | |
var hours = Math.ceil(timeInMs / (1000 * 60 * 60) % 60); | |
var minutes = Math.floor(timeInMs / (1000 * 60) % 60); | |
var seconds = Math.floor(timeInMs / 1000 % 60); | |
hours = hours < 10 ? '0' + hours : hours; | |
minutes = minutes < 10 ? '0' + minutes : minutes; | |
seconds = seconds < 10 ? '0' + seconds : seconds; | |
return hours + delim + minutes + delim + seconds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is my version of it with support for negative values.