This commit is contained in:
parent
bb33335dd4
commit
b8504ac7d0
9 changed files with 13 additions and 34 deletions
16
web/hooks/use-format-time-from-now.ts
Normal file
16
web/hooks/use-format-time-from-now.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { useCallback } from 'react'
|
||||
import { useI18N } from '@/context/i18n'
|
||||
import 'dayjs/locale/zh-cn'
|
||||
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
export const useFormatTimeFromNow = () => {
|
||||
const { locale } = useI18N()
|
||||
const formatTimeFromNow = useCallback((time: number) => {
|
||||
return dayjs(time).locale(locale === 'zh-Hans' ? 'zh-cn' : locale).fromNow()
|
||||
}, [locale])
|
||||
|
||||
return { formatTimeFromNow }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue