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(':'); }
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; }