From bb792a25ae73cd50c7610d06ee06bad787bd370e Mon Sep 17 00:00:00 2001
From: xiebin <123456>
Date: Fri, 05 Aug 2022 17:31:39 +0800
Subject: [PATCH] 时间工具类

---
 src/utils/dateUtils.js |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/utils/dateUtils.js b/src/utils/dateUtils.js
new file mode 100644
index 0000000..9d43dc1
--- /dev/null
+++ b/src/utils/dateUtils.js
@@ -0,0 +1,54 @@
+/**
+ * 根据指定时间去返回天数
+ * @param start 开始时间
+ * @param end 结束时间
+ * @returns {number} 天数
+ */
+function tmpTDiff (start, end) {
+    const d1 = Date.parse(new Date(start))
+    const d2 = Date.parse(new Date(end))
+    // 时间戳相减 / 天数
+    const day = parseInt((d2 - d1) / (1000 * 60 * 60 * 24))
+    return day
+}
+
+/**
+ * 获取多少月前的时间
+ * @param num 多少月
+ * @returns {string} yyyy-MM-dd 00:00:00
+ */
+function getSpecifyMonthDate (num) {
+    const timeCount = new Date().getTime() - num * 30 * 24 * 60 * 60 * 1000
+    const date = new Date(timeCount)
+    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 00:00:00`
+}
+
+/**
+ * 获取多少月前的时间
+ * @param num 多少月
+ * @returns {string} yyyy-MM-dd 00:00:00
+ */
+function getSpecifyDayDate (day) {
+    const timeCount = new Date().getTime() - day * 24 * 60 * 60 * 1000
+    const date = new Date(timeCount)
+    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 00:00:00`
+}
+
+/**
+ * 获取今天最后日期
+ * @returns {string} yyyy-MM-dd 23:59:59
+ */
+function getDayLast () {
+    const date = new Date()
+    const year = date.getFullYear()
+    const month = date.getMonth() + 1
+    const strDate = date.getDate() - 1
+    return `${year}-${month}-${strDate} 23:59:59`
+}
+
+export default {
+    tmpTDiff,
+    getSpecifyMonthDate,
+    getSpecifyDayDate,
+    getDayLast
+}

--
Gitblit v1.9.3