Javascript add leading zeroes to date

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

    var MyDate = new Date();
    var MyDateString = '';
    MyDate.setDate(MyDate.getDate());
    var tempoMonth = (MyDate.getMonth()+1);
    var tempoDate = (MyDate.getDate());
    if (tempoMonth < 10) tempoMonth = '0' + tempoMonth;
    if (tempoDate < 10) tempoDate = '0' + tempoDate;
    MyDateString = tempoDate + '/' + tempoMonth + '/' + MyDate.getFullYear();
    

提交回复
热议问题