Skip to content

Instantly share code, notes, and snippets.

@kalmanolah
Last active January 2, 2016 17:18
Show Gist options
  • Save kalmanolah/8335443 to your computer and use it in GitHub Desktop.
Save kalmanolah/8335443 to your computer and use it in GitHub Desktop.
A little javascript snippet for formatting times in seconds.
function formatTime(secs, format) {
if (!format) {
format = '%hh %mm %ss';
}
var hours = ("0" + Math.floor(secs / 3600)).slice(-2),
minutes = ("0" + Math.floor((secs % 3600) / 60)).slice(-2),
seconds = ("0" + (secs % 60)).slice(-2);
return format
.replace('%h', hours)
.replace('%m', minutes)
.replace('%s', seconds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment