在项目中使用的时间组件获取到的时间格式是这样的:2020-08-06T08:44:40.500Z
但是后台需要的是YY-MM-DD hh:mm:ss格式的数据,接下来我用moment做个简单的转换
const time = '2020-08-06T08:44:40.500Z';
const stringTime = moment(time).format('YYYY-MM-DD hh:mm:ss');
console.log(stringTime); // 2020-08-06 44:40:00
//时间戳转换
const newTime = moment.unix(1602318531).format('YYYY-MM-DD HH:mm:ss');
console.log(newTime); // 2020-08-06 44:40:00
转换之后就得到想要的格式啦 YY-MM-DD hh:mm:ss
更多moment转换方式可以到官网了解:http://momentjs.cn/