Optimize util structure
This commit is contained in:
30
src/util/datetime.tsx
Normal file
30
src/util/datetime.tsx
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user