Recently, I decided to make the switch from using moment.js to Luxon for handling dates and times. With moment.js, I was able to convert a Date()
object to timestamp format like this:
....moment()
.subtract(2, 'hours')
.utc()
.format('YYYY-MM-DD HH:mm:ss [GMT]');
This resulted in a timestamp like: 2022-12-01 17:40:16 GMT
However, after switching to Luxon and reviewing the documentation, I couldn't find a straightforward way to achieve the same result. I tried the following approach:
const tryThis = date.minus({ hours: 2 }).toISO();
const getGMTIntheDate = DateTime.fromISO(tryThis);
const finalResult = getGMTIntheDate.toJSDate().toString();
This code produced a timestamp that looks like:
Thu Dec 01 2022 09:49:44 GMT-0800 (Pacific Standard Time)
I'm wondering if Luxon offers any custom formatting options that I may have overlooked in the documentation?