vue 时间戳转换成日期时间或日期

vue利用filters实现循环时间戳转换日期


你们要的效果:
在这里插入图片描述

js工具类:

// 时间戳转换为日期 --年月日
function unixTimeToDate(unixtime){
	var d = new Date(parseInt(unixtime) * 1000); // 依情况进行更改 * 1
	return (d.getFullYear()) + '-' + (d.getMonth() + 1 > 9 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1)) + '-' + (d.getDate() > 9 ? d.getDate() : '0' + d.getDate());
}
// 时间戳转换为日期时间 --年月日 时分秒
function unixTimeToDateTime(unixtime){
	var now = new Date(unixtime * 1000); // 依情况进行更改 * 1
        y = now.getFullYear();
        m = now.getMonth() + 1;
        d = now.getDate();
        return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
}

filters:

filters: {
            time: (value) => {
            	return unixTimeToDateTime(value);
            }
        }

页面:

{{o.createTime|time}}

就这样
在这里插入图片描述
挺好用的

猜你喜欢

转载自blog.csdn.net/weixin_43760328/article/details/88762274