V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
imherer
V2EX  ›  程序员

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

  •  
  •   imherer · Jun 14, 2024 · 2755 views
    This topic created in 683 days ago, the information mentioned may be changed or developed.

    本地化要支持中文的

    vueuse 的 useTimeAgo 可惜不支持中文呀

    16 replies    2024-06-15 12:30:39 +08:00
    weixind
        1
    weixind  
       Jun 14, 2024
    谜底不就在谜面上么。
    davin
        2
    davin  
       Jun 14, 2024   ❤️ 1
    官方 issue 底下有结合 i18n 的不错的解决方案 /issues/1592
    0x4b0082
        3
    0x4b0082  
       Jun 14, 2024
    date-fns/formatDistance

    如有需要处理成月/年的自己除 30/365 就好 差个一两天没人在意的
    94
        4
    94  
       Jun 14, 2024
    dumbass
        5
    dumbass  
       Jun 14, 2024 via iPhone
    dayjs 好像也支持吧
    butanediol2d
        6
    butanediol2d  
       Jun 14, 2024
    不了解前端,不过应该都有 icu 的 port 吧
    fjc0k
        7
    fjc0k  
       Jun 14, 2024
    跳出 Vue ,它只是个 ui 框架
    NoManPlay
        8
    NoManPlay  
       Jun 14, 2024
    需要现成 hooks 就上面说的 useTimeAgo+i18n
    NoManPlay
        9
    NoManPlay  
       Jun 14, 2024
    laters
        10
    laters  
       Jun 14, 2024
    dayjs
    snowlee
        11
    snowlee  
       Jun 14, 2024
    94
        12
    94  
       Jun 14, 2024
    @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
        13
    thawne  
       Jun 14, 2024
    dayjs
    66beta
        14
    66beta  
       Jun 14, 2024
    `dayjs.updateLocale`
    66beta
        15
    66beta  
       Jun 14, 2024
    @66beta #14 dayjs.updateLocale -> relativeTime
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4966 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 04:01 · PVG 12:01 · LAX 21:01 · JFK 00:01
    ♥ Do have faith in what you're doing.