直播商城系统源码,实现文章更新日期--时间戳

直播商城系统源码,实现文章更新日期--时间戳

Vue.filter('formatTime', function(time) {
const d = new Date(time);
const now = Date.now();
const diff = (now - d) / 1000;
if (diff < 30) {
return "刚刚";
} else if (diff < 3600) {
return Math.ceil(diff / 60) + "分钟前";
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + "小时前";
} else if (diff < 3600 * 24 * 2) {
return "1天前";
} else if (diff < 3600 * 24 * 3) {
return "2天前";
} else if (diff < 3600 * 24 * 4) {
return "3天前";
}
return (
d.getFullYear() + '-' +
(d.getMonth() + 1 < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1) +
"-" +
(d.getDate() < 10 ? '0' + d.getDate() : d.getDate()) +
" " +
(d.getHours() < 10 ? '0' + d.getHours() : d.getHours()) +
":" +
(d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()) +
""
);
})
 

​最终显示 1分钟前、1小时前、1天前…或者具体日期

 以上就是 直播商城系统源码,实现文章更新日期--时间戳,更多内容欢迎关注之后的文章

 

posted @ 2023-06-14 14:03  云豹科技-苏凌霄  阅读(7)  评论(0编辑  收藏  举报