时间格式2020-09-29T18:02:02.000Z转换为“年月日时分秒“
遇到一个需求: 选择时间后打印出来是 “2020-09-29T18:02:02.000Z” 格式的,后台需要转换为 “2020-09-30 02:02:02”格式。 一、2020-09-29T18:02:02.000Z T表示分隔符,Z表示的是UTC。 UTC:世界标准时间,在世界标准时间上加上8小时,即东八区时间,也就是北京时间。 二、 2020-09-29T18:02:02.000Z转换为 2020-09-30 02:02:02 步骤: ①.引入 dayjs (一个轻量的处理时间和日期的javascript库) 下载 npm install dayjs --save main.js 中 全局引入 import dayjs from ‘dayjs’ Vue.prototype.dayjs = dayjs; ②.时间转换函数 // 时间 aaa ( ) { let time = '2020-09-29T18:02:02.000Z' time = this . formateDate ( time ) ; console . log ( form ) ; // 2020-09-30 2:2:2 } , // 时间格式转换 formateDate ( time ) { // 使用dayjs 把世界标准时间转换为北京时间 let date = this . dayjs ( time )