Skip to content

Instantly share code, notes, and snippets.

@kuyseng
Created May 26, 2012 03:36
Show Gist options
  • Save kuyseng/2792011 to your computer and use it in GitHub Desktop.
Save kuyseng/2792011 to your computer and use it in GitHub Desktop.
javascript: format time show rectime record time
function record_time(startTime) {
var secs = Math.round(((new Date()).getTime() - startTime)/1000);
if(secs === 0) return 1;
var str = "",
hr = Math.floor(secs / 3600),
min = Math.floor((secs - (hr * 3600))/60),
sec = secs - (hr * 3600) - (min * 60);
if(hr>0) { str += hr + "h:"; }
if(min>0) { str += min + "mn:"; }
if(sec>0) { str += sec + "s"; }
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment