In the current version of the Chrome browser (v28.0.1496.0), each Number object has a function toPaddedString(n) .
Number(16).toPaddedString(4) "0016"
As for the rather narrow browser, but I doubt it will bring you much benefit. This may be part of the production version of Chrome, but right now I do not have this version. This feature is not part of EcmaScript 5.1, so itโs best not to rely on it. However, this is not [native code] , so ...
Number(1).toPaddedString function g(k,j){var i=this.toString(j||10);return"0".times(ki.length)+i}
So, to use this function in any browser, include this line of code:
Number.prototype.toPaddedString = function g(k,j){var i=this.toString(j||10);return"0".times(ki.length)+i};
Then your month can be supplemented, for example:
var curr_month = d.getMonth().toPaddedString(2);
mwcz
source share