Posted By

nkm on 04/27/10


Tagged

time format timer conversion convert seconds elapsed countDown Stopwatch


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dipser


Timer format


 / Published in: JavaScript
 

Formats a time in Numeric format into Timer format (HH:MM:SS). - Rounds values after conversion - Displays negative values (-HH:MM:SS) - Only displays the hours if necessary - Fails gracefully

  1. function timer_format(sec) {
  2.  
  3. return (sec<0?'-':'')+(new Date(Math.abs(Math.round(sec))*1000 || 0)).toUTCString().match(/[0-9]{2}:[0-9]{2}:[0-9]{2}/).toString().replace(/^00:/, '');
  4. }

Report this snippet  

You need to login to post a comment.