Luxon does not format (DD'MM yyyy) format

9.7k views Asked by At

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
1

There are 1 answers

1
Lionel Rowe On

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('!', "'")