天天看點

javascript 月份兩位表示

var d = new Date();
var formatedMonth = ("0" + (d.getMonth() + 1)).slice(-2);
           

或者

Date.prototype.getMonthFormatted = function() {
var month = this.getMonth() + 1;
return month < 10 ? '0' + month : '' + month; 
}