Skip to content

useTimeAgoIntl

类别
导出大小
1.12 kB
最近修改
2 days ago

支持 i18n 的实时显示时间功能。当时间变化时,时间显示字符串会自动更新。由 Intl.RelativeTimeFormat 提供支持。

🌐 Reactive time ago with i18n supported. Automatically update the time ago string when the time changes. Powered by Intl.RelativeTimeFormat.

示例

English: now, Chinese: 现在
0ms

用法

🌐 Usage

js
import { useTimeAgoIntl } from '@vueuse/core'

const timeAgoIntl = useTimeAgoIntl(new Date(2021, 0, 1))

非反应式用法

🌐 Non-Reactivity Usage

如果你不需要响应性,可以使用 formatTimeAgo 函数获取格式化字符串,而不是 Ref。

🌐 In case you don't need the reactivity, you can use the formatTimeAgo function to get the formatted string instead of a Ref.

js
import { formatTimeAgoIntl } from '@vueuse/core'

const timeAgoIntl = formatTimeAgoIntl(new Date(2021, 0, 1)) // string