先前看到好几种 转换方式

第一种:

一行代码搞定的: 时间格式为  2019-07-01 12:00:00
function time(time = +new Date()) {
console.log(time)
var date = new Date(time + 8 * 3600 * 1000); // 增加8小时
return date.toJSON().substr(0, 19).replace('T', ' ');
}
console.log(time(+new Date("2014-10-01 12:00:00")))//里面穿的格式只要符合要求就行例如: 2014/02/12 2014-12-21 时间不传默认00:00:00

更多文章请关注《万象专栏》