Format time in seconds to HH:MM - Node.js Date

Node.js examples for Date:Time Format

Description

Format time in seconds to HH:MM

Demo Code


  sendsToTime: function(s){
    var h = parseInt(s/3600);
    var m = parseInt((s%3600)/60);
    var HH = null;
    var MM = null;
    if(h>0 && h < 10){
      HH = "0" + h;
    }else if(h == 0){
      HH = "00";/*from  w  w w  .  ja  va 2 s  . c o  m*/
    }else if(h >= 10){
      HH = h + "";
    }
    if(m > 0 && m < 10){
      MM = "0" + m;
    }else if(m == 0){
      MM = "00";
    }else if(m >= 10){
      MM = m + "";
    }    
    return HH+":"+MM;
  },

Related Tutorials