已知,格式化时间: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中 取变量值-》变量.value
      res.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)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐