fix: 添加GetCurrentTime和IsDaysAgo函数,优化时间处理逻辑
This commit is contained in:
parent
509af0f154
commit
34756928dd
@ -1,5 +1,4 @@
|
|||||||
import systemTime from '@ohos.systemDateTime';
|
import systemTime from '@ohos.systemDateTime';
|
||||||
import { timeSynchronization } from '../../api';
|
|
||||||
|
|
||||||
export function isSevenDaysAgo(date, days = 2) {
|
export function isSevenDaysAgo(date, days = 2) {
|
||||||
const today = new Date(); // 当前日期
|
const today = new Date(); // 当前日期
|
||||||
@ -62,15 +61,15 @@ export function dateFormat(t) {
|
|||||||
return year + "-" + fill(month) + "-" + fill(day) + " " + fill(hours) + ":" + fill(minutes) + ":" + fill(seconds);
|
return year + "-" + fill(month) + "-" + fill(day) + " " + fill(hours) + ":" + fill(minutes) + ":" + fill(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dateVersionFormat(t) {
|
// export function dateVersionFormat(t) {
|
||||||
let year = t.getFullYear()
|
// let year = t.getFullYear()
|
||||||
let month = t.getMonth() + 1
|
// let month = t.getMonth() + 1
|
||||||
let day = t.getDate()
|
// let day = t.getDate()
|
||||||
let hours = t.getHours()
|
// let hours = t.getHours()
|
||||||
let minutes = t.getMinutes()
|
// let minutes = t.getMinutes()
|
||||||
let seconds = t.getSeconds()
|
// let seconds = t.getSeconds()
|
||||||
return year + "." + fill(month) + "." + fill(day) + "." + fill(hours);
|
// return year + "." + fill(month) + "." + fill(day) + "." + fill(hours);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//同步时时间
|
//同步时时间
|
||||||
|
|||||||
@ -4,10 +4,21 @@ enum timeType {
|
|||||||
fulltime = 1
|
fulltime = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取当前时间
|
||||||
export function GetCurrentTime(type?: timeType): string {
|
export function GetCurrentTime(type?: timeType): string {
|
||||||
if (type === 1) {
|
if (type === 1) {
|
||||||
return dayTs().format("YYYYMMDDHHmmss")
|
return dayTs().format("YYYYMMDDHHmmss")
|
||||||
} else {
|
} else {
|
||||||
return dayTs().format("YYYY-MM-DD HH:mm:ss")
|
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;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user