在代码中的时间类型经过JSON.stringify()方法后会少8小时,如图:
解决方法如下:
Date.prototype.toJSON = function () {
return moment(this).format('YYYY-MM-DD HH:mm:ss')
}
这里使用了moment方法,使用其他自己方便的方法format也可以
此方法对JSON对象内的对象键值对也有效,如图在加上之前:
加上之后:
在代码中的时间类型经过JSON.stringify()方法后会少8小时,如图:
解决方法如下:
Date.prototype.toJSON = function () {
return moment(this).format('YYYY-MM-DD HH:mm:ss')
}
这里使用了moment方法,使用其他自己方便的方法format也可以
此方法对JSON对象内的对象键值对也有效,如图在加上之前:
加上之后: