前端大佬们有没有好用的 timeago 库

2024-06-14 11:02:06 +08:00
 imherer

本地化要支持中文的

vueuse 的 useTimeAgo 可惜不支持中文呀

2334 次点击
所在节点    程序员
16 条回复
weixind
2024-06-14 11:06:10 +08:00
谜底不就在谜面上么。
davin
2024-06-14 11:08:10 +08:00
官方 issue 底下有结合 i18n 的不错的解决方案 /issues/1592
raphaelsoul
2024-06-14 11:17:52 +08:00
date-fns/formatDistance

如有需要处理成月/年的自己除 30/365 就好 差个一两天没人在意的
dfkjgklfdjg
2024-06-14 11:50:52 +08:00
bojackhorseman
2024-06-14 12:02:47 +08:00
dayjs 好像也支持吧
butanediol2d
2024-06-14 12:08:35 +08:00
不了解前端,不过应该都有 icu 的 port 吧
fjc0k
2024-06-14 12:29:59 +08:00
跳出 Vue ,它只是个 ui 框架
NoManPlay
2024-06-14 13:28:19 +08:00
需要现成 hooks 就上面说的 useTimeAgo+i18n
NoManPlay
2024-06-14 13:28:47 +08:00
laters
2024-06-14 13:59:19 +08:00
dayjs
snowlee
2024-06-14 15:01:59 +08:00
dfkjgklfdjg
2024-06-14 16:02:01 +08:00
@dfkjgklfdjg #4 ,补充一下,useTimeAge 支持传入格式化文本的。
格式看这里 👉 [vueuse/packages/core/useTimeAgo/index.ts at main · vueuse/vueuse]( https://github.com/vueuse/vueuse/blob/main/packages/core/useTimeAgo/index.ts#L92)
thawne
2024-06-14 16:25:59 +08:00
dayjs
66beta
2024-06-14 16:26:48 +08:00
`dayjs.updateLocale`
66beta
2024-06-14 16:27:13 +08:00
@66beta #14 dayjs.updateLocale -> relativeTime
magicdawn
2024-06-15 12:30:39 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1049476

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX