San*_*eep 1 javascript momentjs luxon
根据其文档,moment.js已弃用,因此我在 React 项目中使用了Luxon 。我需要将日期格式化为DD'MM yyyy,Luxon 不接受这种格式,而 MomentJs 成功做到了。如果你们在 Luxon 找到任何方法来处理这个问题,请回答:
MomentJS
moment('06/24/2020').format('DD\'MM yyyy') // output is = 24'06 2020
Run Code Online (Sandbox Code Playgroud)
勒克森
console.warn(DateTime.fromJSDate(new Date("06/24/2020")).toFormat('dd\'MM yyyy')); // output is = 24MM yyyy
Run Code Online (Sandbox Code Playgroud)
Luxon使用单引号作为转义字符,因此当前无法插入文字单引号。根据Luxon GitHub 问题 #649 Escaping single quote,这似乎是一个已知的限制。
除了自己创建 PR 之外,你还可以像这样解决这个问题:
DateTime.fromJSDate(new Date('06/24/2020')).toFormat('dd!MM yyyy')
.replace('!', "'")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9597 次 |
| 最近记录: |