From 5d8e52e398bff7bc8f83e8f5b8a387175b958c98 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 24 二月 2023 10:20:18 +0800
Subject: [PATCH] 2023.2.24
---
utils/util.js | 36 ++++++++++++++++++++++++++++--------
1 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/utils/util.js b/utils/util.js
index cc27905..3aa9e77 100644
--- a/utils/util.js
+++ b/utils/util.js
@@ -1,12 +1,32 @@
-const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
+const moment = require('./moment.min')
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
+
+
+const formatTime = date => {
+ const time = moment(date)
+ const now = moment()
+
+ const timeYear = time.year()
+ const timeMonth = time.month() + 1
+ const timeDay = time.date()
+
+ const thisYear = now.year()
+ const thisMonth = now.month() + 1
+ const thisDay = now.date()
+
+ if (timeYear < thisYear) {
+ return time.format('YYYY-MM-DD')
+ } else if (timeMonth < thisMonth) {
+ return time.format('MM-DD')
+ } else if (timeDay < thisDay) {
+ if (timeDay + 1 == thisDay) {
+ return '鏄ㄥぉ'
+ } else {
+ return time.format('MM-DD')
+ }
+ } else {
+ return time.fromNow()
+ }
}
const formatNumber = n => {
--
Gitblit v1.9.3