Skip to content

Instantly share code, notes, and snippets.

@jluismm2311
Created September 14, 2015 17:49
Show Gist options
  • Save jluismm2311/0e42efd0ea11d1e9c195 to your computer and use it in GitHub Desktop.
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)
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