已知,格式化时间:dayjs(cellValue).format('YYYY-MM-DD')
用法:
import dayjs from 'dayjs';dayjs(时间戳).format('YYYY-MM-DD HH:mm:ss');
如,在get请求中使用:
service.get('/trace/'+sourceSearchInput.value).then(res => {dialogSearchResult.value.push(res); //返回对象,push进去 & vue3中 取变量值-》变量.valueres.createTime = dayjs(res.createTime).format('YYYY-MM-DD HH:mm:ss');res.updateTime = dayjs(res.updateTime).format('YYYY-MM-DD HH:mm:ss')}).catch(error => {ElMessage({type:'error',message:'请输入正确的值'})})
测试代码:
<template><div><el-button @click="bt" type="success"></el-button></div>
</template><script setup>
import dayjs from 'dayjs';
function bt(){alert(dayjs(1651042749000).format('YYYY-MM-DD HH:mm:ss'));
}</script><style lang="less"></style>('YYYY-MM-DD HH:mm:ss');
测试结果 :

dayjs中文官网:Format · Day.js (gitee.io)

















