Created
September 14, 2015 17:49
-
-
Save jluismm2311/0e42efd0ea11d1e9c195 to your computer and use it in GitHub Desktop.
Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS) HH = hours, padded to 2 digits, range: 00 - 99 MM = minutes, padded to 2 digits, range: 00 - 59 SS = seconds, padded to 2 digits, range: 00 - 59 The maximum time never exceeds 359999 (99:59:59)
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
function humanReadable(seconds) { | |
var hours = seconds / 3600, minutes = seconds / 60 % 60, newSeconds = seconds % 60 ; | |
return formatDate(hours) +':' + formatDate(minutes)+':'+formatDate(newSeconds) | |
} | |
function formatDate(n){ | |
var number = Number.parseInt(n) | |
return number > 9? number : '0'+number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment