Nodejs Number Format Pad pad(size)

Here you can find the source of pad(size)

Method Source Code

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);
  while (s.length < (size || 2)) { s = "0" + s; }
  return s;/* w ww.  j  av  a  2  s . co m*/
}

setInterval(() => {
  let diff = moment(TARGET.diff(moment().utc())).utc();

  let h = diff.hours();
  let m = diff.minutes();
  let c = ~~(diff.milliseconds() / 10);
  let s = diff.seconds();
  if (h == 0 && m == 0 && s == 8 && c < 61) {
    countdown.play();
  }
  hh.innerHTML = h.pad(2);
  mm.innerHTML = m.pad(2);
  ss.innerHTML = s.pad(2);
  cc.innerHTML = c.pad(2);
}, 30);

Related

  1. 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;
    
  2. 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){
    ...
    
  3. 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;}
    ...
    
  4. pad(size)
    Number.prototype.pad = function(size) {
        var s = String(this);
        while (s.length < (size || 2)) {s = "0" + s;}
        return s;
    module.exports = {
        format: {
            timestamptz: function(date) {
                const YYYY = date.getFullYear();
    ...
    
  5. pad(size)
    Number.prototype.pad = function(size) {
        var s = String(this);
        while (s.length < (size || 2)) {s = "0" + s;}
        return s;
    
  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)
    '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;
    
  8. pad(size)
    Number.prototype.pad = function(size) {
      var s = String(this);
      if (typeof(size) !== "number") {
        size = 2;
      while (s.length < size) {
        s = "0" + s;
      return s;
    ...
    
  9. pad(size, decimalSize, decimalChar)
    Number.prototype.pad = function (size, decimalSize, decimalChar) {
        if (!decimalChar) decimalChar = '.';
        var str = this.toString();
        str = str.split(".");
        var result = str[0].pad("0", size ? size : 0);
        if (str.length==2){
            result += decimalChar + str[1].pad("0", decimalSize, true);
        return result;
    ...