admin 管理员组

文章数量: 1086019

moment.js deprecated according to its documentation, So I used Luxon in my react project. I need to format the date like DD'MM yyyy, Luxon does not accept this format while MomentJs successfully did it. If you guys find any way to handle this in Luxon please answer:

MomentJS

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

Luxon

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

moment.js deprecated according to its documentation, So I used Luxon in my react project. I need to format the date like DD'MM yyyy, Luxon does not accept this format while MomentJs successfully did it. If you guys find any way to handle this in Luxon please answer:

MomentJS

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

Luxon

console.warn(DateTime.fromJSDate(new Date("06/24/2020")).toFormat('dd\'MM yyyy')); // output is = 24MM yyyy
Share Improve this question asked Sep 27, 2020 at 10:05 SandeepSandeep 1,4791 gold badge13 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Luxon uses single quotes as an escape character, so it's currently not possible to insert a literal single quote. According to Luxon GitHub issue #649 Escaping single quote, it seems like this is a known limitation.

Short of opening a PR yourself, you could work around it like this:

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

本文标签: javascriptLuxon does not format (DD39MM yyyy) formatStack Overflow