1.新建一个js文件用来存放时间格式的代码

代码如下:

export function timestampToTime(timestamp) {
    let now = new Date(timestamp*1000);
    let year = now.getFullYear();    
    let month = now.getMonth()+1;    
    let date = now.getDate();    
    let hour = now.getHours();    
    let minute = now.getMinutes();    
    let second = now.getSeconds();    
    return year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;
}

2.在需要对时间戳进行格式化处理的组件中引入上面的js文件

代码如下(示例):

import {timestampToTime} from "@/src/utils/formdate.js"
//对时间进行格式化
date=timestampToTime(time)
Logo

前往低代码交流专区

更多推荐