Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Created June 29, 2014 21:41
Show Gist options
  • Select an option

  • Save Ciantic/cc28a36bd40a5d3f3493 to your computer and use it in GitHub Desktop.

Select an option

Save Ciantic/cc28a36bd40a5d3f3493 to your computer and use it in GitHub Desktop.
Format time HH:MM
// total in seconds
function formatTime(total: number): string {
// If the number is float ceiling gives best result
var total = Math.ceil(total),
mins = Math.floor(total / 60),
secs = Math.floor(total - mins * 60),
m = ("000" + mins).slice(-2),
s = ("000" + secs).slice(-2);
return m + ":" + s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment