Javascript add leading zeroes to date

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

    You can provide options as a parameter to format date. First parameter is for locale which you might not need and second is for options. For more info visit https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

    var date = new Date(Date.UTC(2012, 1, 1, 3, 0, 0));
    var options = { year: 'numeric', month: '2-digit', day: '2-digit' };
    console.log(date.toLocaleDateString(undefined,options));
    

提交回复
热议问题