Feat: frontend support timezone of timestamp (#4070)

This commit is contained in:
KVOJJJin 2024-05-04 16:15:32 +08:00 • committed by GitHub
commit c0476c7881
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 88 additions and 58 deletions

View file

@ -0,0 +1,21 @@
'use client'
import { useCallback } from 'react'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
import { useAppContext } from '@/context/app-context'
dayjs.extend(utc)
dayjs.extend(timezone)
const useTimestamp = () => {
const { userProfile: { timezone } } = useAppContext()
const formatTime = useCallback((value: number, format: string) => {
return dayjs.unix(value).tz(timezone).format(format)
}, [timezone])
return { formatTime }
}
export default useTimestamp