Date.prototype.format = function () {
let year = this.getFullYear() + "-";
let month = (this.getMonth() + 1 + "").padStart(2, "0") + "-";
let day = (this.getDate() + "").padStart(2, "0");
return year + month + day;
};
let now = new Date();
let stringDate = now.format();
console.log(stringDate);
let now1 = new Date(1997, 1, 28);
console.log(now1.format());
利用对象原型格式化输出当前日期
最新推荐文章于 2024-10-01 20:12:28 发布