这是 IE 11 中的错误吗?
Is this a bug in IE 11?
console.log(
('00' + (new Date('3/4/2019')).toLocaleDateString("en-US").split('/')[1]).slice(-2)
);
IE:
"4"
Chrome
"04"
解决方法是什么?
为什么不直接从对象 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
console.log(
('00' + (new Date('3/4/2019')).toLocaleDateString("en-US").split('/')[1]).slice(-2)
);
IE:
"4"
Chrome
"04"
解决方法是什么?
为什么不直接从对象 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