Skip to content

Instantly share code, notes, and snippets.

@RohitRox
Created April 15, 2013 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitRox/5386285 to your computer and use it in GitHub Desktop.
Save RohitRox/5386285 to your computer and use it in GitHub Desktop.
js string helper for string to hh:mm:ss
String.prototype.toHHMMSS = function () {
sec_numb = parseInt(this);
var hours = Math.floor(sec_numb / 3600);
var minutes = Math.floor((sec_numb - (hours * 3600)) / 60);
var seconds = sec_numb - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
var time = hours+':'+minutes+':'+seconds;
return time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment