From 34756928ddc88efa5d3e2bfcd1d64b0e913b5edf Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Mon, 24 Mar 2025 14:28:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0GetCurrentTime?= =?UTF-8?q?=E5=92=8CIsDaysAgo=E5=87=BD=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/utils/tools.ts | 19 +++++++++---------- entry/src/main/ets/utils/Common.ets | 11 +++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/entry/src/main/ets/common/utils/tools.ts b/entry/src/main/ets/common/utils/tools.ts index 642a4a16..5164af10 100644 --- a/entry/src/main/ets/common/utils/tools.ts +++ b/entry/src/main/ets/common/utils/tools.ts @@ -1,5 +1,4 @@ import systemTime from '@ohos.systemDateTime'; -import { timeSynchronization } from '../../api'; export function isSevenDaysAgo(date, days = 2) { const today = new Date(); // 当前日期 @@ -62,15 +61,15 @@ export function dateFormat(t) { return year + "-" + fill(month) + "-" + fill(day) + " " + fill(hours) + ":" + fill(minutes) + ":" + fill(seconds); } -export function dateVersionFormat(t) { - let year = t.getFullYear() - let month = t.getMonth() + 1 - let day = t.getDate() - let hours = t.getHours() - let minutes = t.getMinutes() - let seconds = t.getSeconds() - return year + "." + fill(month) + "." + fill(day) + "." + fill(hours); -} +// export function dateVersionFormat(t) { +// let year = t.getFullYear() +// let month = t.getMonth() + 1 +// let day = t.getDate() +// let hours = t.getHours() +// let minutes = t.getMinutes() +// let seconds = t.getSeconds() +// return year + "." + fill(month) + "." + fill(day) + "." + fill(hours); +// } //同步时时间 diff --git a/entry/src/main/ets/utils/Common.ets b/entry/src/main/ets/utils/Common.ets index 8c15183c..aae81ac8 100644 --- a/entry/src/main/ets/utils/Common.ets +++ b/entry/src/main/ets/utils/Common.ets @@ -4,10 +4,21 @@ enum timeType { fulltime = 1 } +// 获取当前时间 export function GetCurrentTime(type?: timeType): string { if (type === 1) { return dayTs().format("YYYYMMDDHHmmss") } else { return dayTs().format("YYYY-MM-DD HH:mm:ss") } +} + +//是否是多少天前 +export function IsDaysAgo(date: string | number | Date, days: number = 2): boolean { + const today = dayTs(); // 当前日期 + const target = dayTs(date).format("YYYY-MM-DD HH:mm:ss.SSS"); // 需要判断的日期 + // 计算两个日期之间的差异天数 + const diffDays = today.diff(target, 'day'); + // 如果差异天数大于等于指定天数,则返回 true + return diffDays >= days; } \ No newline at end of file