Format time as HH:MM:SS format - Node.js Date

Node.js examples for Date:Time Format

Description

Format time as HH:MM:SS format

Demo Code


function get_HH_MM_SS(time_ms){
  var seconds=Math.floor(time_ms);
  var minutes=Math.floor(seconds/60);
  var hours=Math.floor(minutes/60);

  minutes=minutes-(hours*60);// www.j  a va  2s. co  m
  seconds=seconds-((minutes*60) + (hours * 3600));

  strhours=hours.toString()
  strminutes=minutes.toString()
  strseconds=seconds.toString()

  if (strseconds.length==1)
    strseconds="0"+strseconds
    
  if (strminutes.length==1)
    strminutes="0"+strminutes
    
  if (strhours.length==1)
    strhours="0"+strhours

  return(strhours+":"+strminutes+":"+strseconds) 
}

Related Tutorials