From 932c3ab49ea4e911fb2c2531c29d6609ac5afefd Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期四, 02 一月 2025 10:51:37 +0800
Subject: [PATCH] itemchart bug修复。 页面优化

---
 src/utils/dateUtil.ts |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/src/utils/dateUtil.ts b/src/utils/dateUtil.ts
index 316b870..a136ed7 100644
--- a/src/utils/dateUtil.ts
+++ b/src/utils/dateUtil.ts
@@ -6,6 +6,7 @@
 
 const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
 const DATE_FORMAT = 'YYYY-MM-DD'
+const DATE_TIME_PATTERN_STRING = 'YYYYMMDDHHmmss'
 
 export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
   return dayjs(date).format(format)
@@ -15,4 +16,39 @@
   return dayjs(date).format(format)
 }
 
+export function formatToDateString(date?: dayjs.ConfigType, format = DATE_TIME_PATTERN_STRING): string {
+  return dayjs(date).format(format)
+}
+
 export const dateUtil = dayjs
+
+export function getYMDHMS (timestamp: number | string | Date) {
+  const time = new Date(timestamp)
+  const year = time.getFullYear()
+  let month = time.getMonth() + 1 + ''
+  let date = time.getDate() + ''
+  let hours = time.getHours() + ''
+  let minute = time.getMinutes() + ''
+  let second = time.getSeconds() + ''
+
+  if (month < 10) { month = '0' + month }
+  if (date < 10) { date = '0' + date }
+  if (hours < 10) { hours = '0' + hours }
+  if (minute < 10) { minute = '0' + minute }
+  if (second < 10) { second = '0' + second }
+  return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
+}
+export function getYMDHM0 (timestamp: number | string | Date) {
+  const time = new Date(timestamp)
+  const year = time.getFullYear()
+  let month = time.getMonth() + 1 + ''
+  let date = time.getDate() + ''
+  let hours = time.getHours() + ''
+  let minute = time.getMinutes() + ''
+
+  if (month < 10) { month = '0' + month }
+  if (date < 10) { date = '0' + date }
+  if (hours < 10) { hours = '0' + hours }
+  if (minute < 10) { minute = '0' + minute }
+  return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + '00'
+}

--
Gitblit v1.9.3