【问题标题】:Luxon does not format (DD'MM yyyy) formatLuxon 不格式化 (DD'MM yyyy) 格式
【发布时间】:2021-01-13 03:41:06
【问题描述】:

moment.js 根据其文档已弃用,因此我在我的反应项目中使用了Luxon。我需要像 DD'MM yyyy 那样格式化日期,Luxon 不接受这种格式,而 MomentJs 成功地做到了。如果你们找到任何在 Luxon 中处理此问题的方法,请回答:

MomentJS

moment('06/24/2020').format('DD\'MM yyyy')  // output is = 24'06 2020

卢克森

console.warn(DateTime.fromJSDate(new Date("06/24/2020")).toFormat('dd\'MM yyyy')); // output is = 24MM yyyy

【问题讨论】:

    标签: javascript momentjs luxon


    【解决方案1】:

    Luxon uses single quotes as an escape character,因此目前无法插入文字单引号。根据Luxon GitHub issue #649 Escaping single quote 的说法,这似乎是一个已知的限制。

    不用自己开公关,你可以像这样解决它:

    DateTime.fromJSDate(new Date('06/24/2020')).toFormat('dd!MM yyyy')
        .replace('!', "'")
    

    【讨论】:

    • 谢谢!这是完美的答案。 +1
    猜你喜欢
    • 2021-08-30
    • 2021-08-13
    • 2021-05-20
    • 2021-07-28
    • 2022-08-19
    • 2021-01-11
    • 2020-10-23
    • 2021-12-12
    • 1970-01-01
    相关资源
    最近更新 更多