Skip to content

Instantly share code, notes, and snippets.

@denniszhao
Created January 13, 2015 05:41
Show Gist options
  • Save denniszhao/3faa9ad74383274d004c to your computer and use it in GitHub Desktop.
Save denniszhao/3faa9ad74383274d004c to your computer and use it in GitHub Desktop.
formatTime
/**
* Formats number of seconds to hh:mm:ss format.
*/
formatTime: function (seconds) {
var minutes = Math.floor(seconds / 60),
hours = Math.floor(minutes / 60),
h = (hours !== 0) ? hours + ":" : "",
m = (minutes % 60 !== 0) ? (minutes % 60) + ":" : ((h === "") ? "" : "00:"),
s = (seconds % 60 !== 0) ? (seconds % 60) : "00";
return h + m + s;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment