toLocaleString()函数用于以字符串的形式返回当前Date对象
Date.prototype.toLocaleString = function() {
return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate();
};
使用 new Date().toLocaleString() 得到如下图

或者 new Date(时间戳).toLocaleString() 得到

博客介绍了JavaScript中日期格式转换的方法,可使用new Date().toLocaleString() ,也能通过new Date(时间戳).toLocaleString() 来实现日期格式转换。
605

被折叠的 条评论
为什么被折叠?



