From 53bcb7e5dffa071d2c6593f5db7f0b6e4e2f8dfe Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Wed, 18 Oct 2023 16:17:02 +0800
Subject: [PATCH] 隐藏重复定时和连续执行
---
src/utils/time.ts | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/utils/time.ts b/src/utils/time.ts
index 31f3717..72a311d 100644
--- a/src/utils/time.ts
+++ b/src/utils/time.ts
@@ -13,3 +13,56 @@
export function formatUnixTime (time: number, format = DATE_FORMAT): string {
return time ? moment.unix(time).format(format) : DEFAULT_PLACEHOLDER
}
+
+export function dateFormat (date:any, format:string) {
+ format = format || 'yyyy-MM-dd hh:mm:ss'
+ if (date !== 'Invalid Date') {
+ const o = {
+ 'M+': date.getMonth() + 1, // month
+ 'd+': date.getDate(), // day
+ 'h+': date.getHours(), // hour
+ 'm+': date.getMinutes(), // minute
+ 's+': date.getSeconds(), // second
+ 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter
+ S: date.getMilliseconds() // millisecond
+ }
+ if (/(y+)/.test(format)) {
+ format = format.replace(RegExp.$1,
+ (date.getFullYear() + '').substr(4 - RegExp.$1.length))
+ }
+ for (const k in o) {
+ if (new RegExp('(' + k + ')').test(format)) {
+ format = format.replace(RegExp.$1,
+ RegExp.$1.length === 1
+ ? o[k]
+ : ('00' + o[k]).substr(('' + o[k]).length))
+ }
+ }
+ return format
+ }
+ return ''
+}
+
+export function convertTimestampToDate (timestamp:any, format:string) {
+ if (timestamp && (typeof timestamp === 'string') && timestamp.indexOf('-') > -1) {
+ // eslint-disable-next-line no-useless-escape
+ timestamp = timestamp.replace(/\-/g, '/')
+ }
+ const time = new Date(timestamp)
+ const formatterTime = dateFormat(time, format)
+ return formatterTime
+}
+
+// 返回年月日
+export const timestampToTime = (timestamp:number) => {
+ if (!timestamp) return
+ // 时间戳为10位需*1000,时间戳为13位不需乘1000
+ const date = new Date(timestamp)
+ const Y = date.getFullYear() + '-'
+ const M =
+ (date.getMonth() + 1 < 10
+ ? '0' + (date.getMonth() + 1)
+ : date.getMonth() + 1) + '-'
+ const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
+ return Y + M + D
+}
--
Gitblit v1.9.3