const filterTime = (val) => {
console.log(val);
let result;
let timePublish = new Date(val); // 传入的时间
let timeNow = new Date(); // 现在的时间
let minute = 1000 * 60;
let hour = minute * 60;
let day = hour * 24;
let month = day * 30;
let year = month * 12;
let diffValue = timeNow - timePublish; // 时间相差的值,是毫秒
console.log(diffValue);
let diffMonth = diffValue / month;
let diffWeek = diffValue / (7 * day);
let diffDay = diffValue / day;
let diffHour = diffValue / hour;
let diffMinute = diffValue / minute;
let diffYear = diffValue / year;
if (diffValue < minute) {
result = "刚刚";
} else if (diffYear > 1) {
result = parseInt(diffYear) + "年前";
} else if (diffMonth > 1) {
result = parseInt(diffMonth) + "月前";
} else if (diffWeek > 1) {
result = parseInt(diffWeek) + "周前";
} else if (diffDay > 1) {
result = parseInt(diffDay) + "天前";
} else if (diffHour > 1) {
result = parseInt(diffHour) + "小时前";
} else if (diffMinute > 1) {
result = parseInt(diffMinute) + "分钟前";
}
return result;
};
时间过滤器
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.day.js下载与安装:https://dayjs.fenxianglu.cn/category/ 例如:在v...