格式化UTC时间
1.引入第三方包 dayjs (一个轻量的处理时间和日期的javascript库)
(1)下载 npm install/ i dayjs --save
(2). main.js 中全局引入
import dayjs from 'dayjs
Vue.prototype.dayjs=dayjs
- 在使用页面中加入函数
timeTranslate(val) {
var utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
return this.dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss')
},
3.展示调用函数
<el-table-column label="创建时间" align="center" prop="startTime" width="180">
<template slot-scope="scope">
<span>{{timeTranslate(scope.row.startTime)}}</span>
</template>
</el-table-column>
4.官方文档
https://dayjs.fenxianglu.cn/category/
5.引用官方方法
var utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
// 默认当地时间
dayjs().format() //2019-03-06T17:11:55+08:00
// UTC 模式
dayjs.utc().format() // 2019-03-06T09:11:55Z
// 将本地时间转换成 UTC 时间
dayjs().utc().format() // 2019-03-06T09:11:55Z
// 在 UTC 模式下,所有的展示方法都将使用 UTC 而不是本地时区
// 所有的 get 和 set 方法也都会使用 Date#getUTC* 和 Date#setUTC* 而不是 Date#get* and Date#set*
dayjs.utc().isUTC() // true
dayjs.utc().local().format() //2019-03-06T17:11:55+08:00
dayjs.utc('2018-01-01', 'YYYY-MM-DD') // with CustomParseFormat plugin