Javascript Number padLeft(base, chr)

Description

Javascript Number padLeft(base, chr)


Number.prototype.padLeft = function (base, chr) {
    var len = (String(base || 10).length - String(this).length) + 1;
    return len > 0 ? new Array(len).join(chr || '0') + this : this;
}
function formatDate(d) {
    return [(d.getFullYear()).padLeft(),
            (d.getMonth() + 1).padLeft(),
            d.getDate().padLeft()].join('-') +
        ' ' +/*from   w  ww . jav  a2 s.c  om*/
        [d.getHours().padLeft(),
            d.getMinutes().padLeft()].join(':');
}

Javascript Number padLeft(base,chr)


Number.prototype.padLeft = function(base,chr){
   var  len = (String(base || 10).length - String(this).length)+1;
   return len > 0? new Array(len).join(chr || '0')+this : this;
}



PreviousNext

Related