Nodejs Number Format Pad pad(size)

Here you can find the source of pad(size)

Method Source Code

Number.prototype.pad = function(size) {
    var s = String(this);
    while (s.length < (size || 2)) {s = "0" + s;}
    return s;/*  ww w .j ava2  s .  c  om*/
  }

module.exports = {
    format: {
        timestamptz: function(date) {
            //Format is YYYY-MM-DD HH24:MI:SS-TZ

            const YYYY = date.getFullYear();
            const MM = date.getMonth() + 1;
            const DD = date.getDate();

            const HH24 = date.getHours();
            const MI = date.getMinutes();
            const SS = date.getSeconds();

            const TZ = (date.getTimezoneOffset()/60).pad(2);

            return  YYYY + '-' + MM + '-' + DD + ' ' +
                    HH24 + ':' + MI + ':' + SS + '-' +
                    TZ;

        }
    }
}

Related

  1. pad(n, p)
    Number.prototype.pad = function(n, p) {
      var s = '' + this;
      p = p || '0';
      while (s.length < n) s = p + s;
      return s;
    
  2. pad(size)
    Number.prototype.pad = function(size) {
      var s = String(this);
      while (s.length < (size || 2)) { s = '0' + s; }
      return s;
    };
    
  3. pad(size)
    Number.prototype.pad = function(size){
          if(typeof(size) !== "number"){size = 2;}
          var s = String(this);
          while (s.length < size) s = "0" + s;
          return s;
    
  4. pad(size)
    Number.prototype.pad = function(size) {
      var s = String(this);
      while (s.length < (size || 2)) {s = "0" + s;}
      return s;
    function getHashValue(){
      return window.location.hash.substr(1);
    function getHumanTime(timeInSec){
    ...
    
  5. pad(size)
    var util = require('util');
    exports.dayBeginDate = function() {
      var now = new Date();
      var dayBegin = Math.floor(now/1000) - now.getHours()*3600 - now.getMinutes()*60 - now.getSeconds();
      return dayBegin;
    Number.prototype.pad = function(size) {
      var s = String(this);
      if(typeof(size) !== "number"){size = 2;}
    ...
    
  6. pad(size)
    Number.prototype.pad = function(size) {
        var s = String(this);
        while (s.length < (size || 2)) {s = "0" + s;}
        return s;
    
  7. pad(size)
    import moment from "moment";
    const TARGET = moment('2015-11-28 21:30:00+0100').utc();
    let hh = document.getElementById('H');
    let mm = document.getElementById('M');
    let ss = document.getElementById('s');
    let cc = document.getElementById('cs');
    let countdown = document.getElementById('countdown');
    Number.prototype.pad = function(size) {
      var s = String(this);
    ...
    
  8. pad(size)
    Number.prototype.pad = function(size) {
      var s = String(this);
      while (s.length < (size || 2)) {
        s = "0" + s;
      return s;
    
  9. pad(size)
    'use strict';
    Number.prototype.pad = function(size) {
      if(typeof(size) !== "number"){size = 2;}
      var s = String(this);
      while (s.length < size) s = "0" + s;
      return s;