1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Vue 中格式化UTC时间 将-09-05T09:08:03.000Z 转换成 YYYY-MM-DD HH:mm:ss

Vue 中格式化UTC时间 将-09-05T09:08:03.000Z 转换成 YYYY-MM-DD HH:mm:ss

时间:2023-09-28 09:55:10

相关推荐

Vue 中格式化UTC时间 将-09-05T09:08:03.000Z 转换成 YYYY-MM-DD HH:mm:ss

格式化UTC时间

1.引入第三方包 dayjs (一个轻量的处理时间和日期的javascript库)

(1)下载 npm install/ i dayjs --save

(2). main.js 中全局引入

import dayjs from 'dayjsVue.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.官方文档

/category/

5.引用官方方法

var utc = require('dayjs/plugin/utc')dayjs.extend(utc)// 默认当地时间dayjs().format() //-03-06T17:11:55+08:00// UTC 模式dayjs.utc().format() // -03-06T09:11:55Z// 将本地时间转换成 UTC 时间dayjs().utc().format() // -03-06T09:11:55Z // 在 UTC 模式下,所有的展示方法都将使用 UTC 而不是本地时区// 所有的 get 和 set 方法也都会使用 Date#getUTC* 和 Date#setUTC* 而不是 Date#get* and Date#set*dayjs.utc().isUTC() // truedayjs.utc().local().format() //-03-06T17:11:55+08:00dayjs.utc('-01-01', 'YYYY-MM-DD') // with CustomParseFormat plugin

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。