Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Last active April 18, 2016 18:02
Show Gist options
  • Select an option

  • Save bitdivine/7d6df41fb4eac20379d824068cd6a7bd to your computer and use it in GitHub Desktop.

Select an option

Save bitdivine/7d6df41fb4eac20379d824068cd6a7bd to your computer and use it in GitHub Desktop.
Format time intervals as HH:MM:SS
function formatTimeInterval(seconds){
seconds = Number(seconds);
return [60,60,Infinity].map((max) => { var part = seconds % max; seconds -= part; seconds /= max; return part; }).reverse().map((n)=>('00'+n).replace(/^0*([0-9][0-9])/,(m,g1)=>g1).replace(/([.]...).*/,(m,g)=>g)).join(':');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment