mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 19:36:53 +08:00
Feat: frontend support timezone of timestamp (#4070)
This commit is contained in:
21
web/hooks/use-timestamp.ts
Normal file
21
web/hooks/use-timestamp.ts
Normal 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
|
||||
Reference in New Issue
Block a user