【问题标题】:momentjs get localized format with month and days onlymomentjs 仅获取月份和日期的本地化格式
【发布时间】:2023-02-20 17:48:55
【问题描述】:

当与 .format('ll') 一起使用时,我得到一年后缀,如何修复以上内容以将其删除?

例如:2018 年 1 月 29 日 -> 1 月 29 日

我尝试用正则替换,但是比较复杂。

moment().format('ll').replace(new RegExp('[^\.]?' + moment().format('YYYY') + '.?'), '')

2018 年 1 月 29 日 -> 1 月 29 日,

参考:https://github.com/moment/moment/issues/3341

【问题讨论】:

    标签: javascript


    【解决方案1】:
    moment().format('ll')                                                
    .replace(moment().format('YYYY'), '') // remove year
    .replace(/ss+/g, ' ')// remove double spaces, if any
    .trim() // remove spaces from the start and the end
    .replace(/[рг]./, '') // remove year letter from RU/UK locales
    .replace(/de$/, '') // remove year prefix from PT
    .replace(/b.$/, '') // remove year prefix from SE
    .trim() // remove spaces from the start and the end
    .replace(/,$/g, '')
    

    感谢:Localizing day and month in moment.js

    【讨论】:

      猜你喜欢
      • 2020-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多