Javascript add leading zeroes to date

后端 未结 25 1872
执笔经年
执笔经年 2020-11-22 02:50

I\'ve created this script to calculate the date for 10 days in advance in the format of dd/mm/yyyy:

var MyDate = new Date();
var MyDateString = new Date();
M         


        
25条回答
  •  遥遥无期
    2020-11-22 03:20

    try this for a basic function, no libraries required

    Date.prototype.CustomformatDate = function() {
     var tmp = new Date(this.valueOf());
     var mm = tmp.getMonth() + 1;
     if (mm < 10) mm = "0" + mm;
     var dd = tmp.getDate();
     if (dd < 10) dd = "0" + dd;
     return mm + "/" + dd + "/" + tmp.getFullYear();
    };
    

提交回复
热议问题