[英] Javascript add leading zeroes to date
我创建了这个脚本,以dd/mm/yyyy格式提前10天计算日期:
var MyDate = new Date();
var MyDateString = new Date();
MyDate.setDate(MyDate.getDate()+10);
MyDateString = MyDate.getDate() + '/' + (MyDate.getMonth()+1) + '/' + MyDate.getFullYear();
通过将这些规则添加到脚本中,我需要让日期在日和月组件上显示前导零.我好像不能让它起作用.
if (MyDate.getMonth < 10)getMonth = '0' + getMonth;
和
if (MyDate.getDate <10)get.Date = '0' + getDate;
如果有人能告诉我在哪里把这些插入到脚本中,我会非常感激的.