console.log(
('00' + (new Date('3/4/2019')).toLocaleDateString("en-US").split('/')[1]).slice(-2)
);
IE:
"4"
Chrome
"04"
解决方法是什么?
答案 0 :(得分:3)
为什么不仅仅从对象Date的可用方法中获取帮助。
var day = new Date('3/4/2019').getDate();
console.log(day >= 10 ? day : ("0" + day)); // We can use String.prototype.padStart(2, "0"), however, that's not available in IE11