Optimize util structure

This commit is contained in:
2023-11-30 13:57:45 +08:00
parent bf8f915b15
commit f595cb380a
19 changed files with 285 additions and 285 deletions

30
src/util/datetime.tsx Normal file
View File

@@ -0,0 +1,30 @@
import moment from 'moment/moment'
import dayjs from 'dayjs'
export const getNowLocalTime = (format: string = 'yyyy-MM-DD HH:mm:ssZ') => {
return moment().local().format(format)
}
export const getNowUtc = () => {
return moment().toISOString()
}
export const utcToLocalTime = (utcTime: string, format: string = 'yyyy-MM-DD HH:mm:ssZ') => {
return moment.utc(utcTime).local().format(format)
}
export const dayjsToLocalTime = (date: dayjs.Dayjs, format: string = 'YYYY-MM-DD HH:mm:ssZ') => {
return date.format(format)
}
export const dayjsToUtc = (date: dayjs.Dayjs) => {
return date.toISOString()
}
export const localTimeToUtc = (localTime: string) => {
return moment(localTime).toISOString()
}
export const isPastTime = (utcTime: string) => {
return moment.utc(utcTime).isBefore(moment.now())
}