diff --git a/pagesInn/inn/innInfoDetail.vue b/pagesInn/inn/innInfoDetail.vue index 05ceb50..5ffa3f4 100644 --- a/pagesInn/inn/innInfoDetail.vue +++ b/pagesInn/inn/innInfoDetail.vue @@ -255,33 +255,27 @@ export default { * 1. 小于1分钟,显示刚刚 * 2. 小于1小时,显示xx分钟前 * 3. 小于1天,显示xx小时前 - * 4. 小于1月,显示xx天前 - * 5. 小于1年,显示xx月前 - * 6. 大于1年,显示xxxx年xx月xx日 - * 7. 其他,显示xxxx-xx-xx + * 4. 超过7天,显示日期 xxxx年xx月xx日 */ formatterTime(time) { const now = new Date(); const date = new Date(time); - const diff = now - date; // 时间差 - const diffDay = diff / (1000 * 60 * 60 * 24); // 天数 - const diffHour = diff / (1000 * 60 * 60); // 小时 - const diffMinute = diff / (1000 * 60); // 分钟 - if (diffMinute < 1) { - return '刚刚'; + const diff = now - date; + const diffMin = Math.floor(diff / 1000 / 60); + const diffHour = Math.floor(diff / 1000 / 60 / 60); + const diffDay = Math.floor(diff / 1000 / 60 / 60 / 24); + if (diffMin < 1) { + return "刚刚"; } else if (diffHour < 1) { - return `${Math.floor(diffMinute)}分钟前`; + return diffMin + "分钟前"; } else if (diffDay < 1) { - return `${Math.floor(diffHour)}小时前`; - } else if (diffDay < 30) { - return `${Math.floor(diffDay)}天前`; - } else if (diffDay < 365) { - return `${Math.floor(diffDay / 30)}月前`; - } else if (diffDay < 365 * 10) { - return `${Math.floor(diffDay / 365)}年前`; + return diffHour + "小时前"; + } else if (diffDay < 7) { + return diffDay + "天前"; } else { - return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; + return date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日"; } + }, /** * 发评论