Javascript add leading zeroes to date

后端 未结 25 2223
执笔经年
执笔经年 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:38

     let date = new Date();
     let dd = date.getDate();//day of month
    
     let mm = date.getMonth();// month
     let yyyy = date.getFullYear();//day of week
     if (dd < 10) {//if less then 10 add a leading zero
         dd = "0" + dd;
       }
     if (mm < 10) {
        mm = "0" + mm;//if less then 10 add a leading zero
      }
    

提交回复
热议问题