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