How to format a Date with Luxon?

DoneDeal0 picture DoneDeal0 · Sep 25, 2020 · Viewed 19.7k times · Source

With moment.js, you can format a date this way:

How to do the same thing with Luxon? I've tried:

const date = luxon.DateTime.fromISO("2010-10-22T21:38:00" );
const data = luxon.DateTime.fromFormat(date, "DATETIME_SHORT")
// output => script error
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js"></script>

Answer

PatricNox picture PatricNox · Sep 25, 2020
const date = DateTime.fromISO("2010-10-22T21:38:00")
const humanReadable = date.toLocaleString(DateTime.DATETIME_MED);

console.log(humanReadable); // =>  October 22, 9:38 PM

Source: https://github.com/moment/luxon/blob/master/docs/formatting.md

You can read more about the possible formats here: https://github.com/moment/luxon/blob/master/docs/formatting.md#the-basics