NodeJS的日期类型缺省显示的格式是怎么来的
执行 console.log(new Date)会显示类似:2017年09月12日T02:22:34.806Z 这样格式的字符串,我想替换成 2017年09月12日 02:22:34,但是不知道调用啥方法得到前面的格式,有谁知道不?谢谢:)
6 回复
Date.prototype.toString=function(){
return `${this.getFullYear()}-${(this.getMonth()+1+'').padStart(2,'0')}-${(''+this.getDate()).padStart(2,'0')} ${(''+this.getHours()).padStart(2,'0')}:${(''+this.getMinutes()).padStart(2,'0')}:${(''+this.getSeconds()).padStart(2,'0')}`;
}
在chrome里可以直接输出,node里还是要toString或者+’’