Convert Number to HHMMSS - Node.js Number

Node.js examples for Number:Format

Description

Convert Number to HHMMSS

Demo Code

Number.prototype.toHHMMSS = function () {
  var hours = Math.floor(this / 3600);
  var minutes = Math.floor((this - (hours * 3600)) / 60);
  var seconds = this - (hours * 3600) - (minutes * 60);
  
  var time = '';
  if (hours > 0) {
    if (hours < 10) {
      time += '0';
    }/*from w w w . j av  a 2 s  .  co  m*/
    time += hours + ':';
  }
  if (minutes < 10) {
    time += '0';
  }
  time += minutes + ':';
  if (seconds < 10) {
    time += '0';
  }
  time += seconds;
  return time;
};

Related Tutorials