Using Luxon JS, I’ve been trying to format datetime to output in a certain format, using the native toISO function:
This is what I get:
And this is what I want:
I know that they are both equivalent in terms of unix time and mean the same thing except in a different format, I just want to be able to out the second string rather than the first. I looked through the Luxon docs but was unable to find any arguments/options that would give me what I need.
As other already stated in the comments, you can use 2 approaches:
Convert Luxon DateTime to UTC using
"Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
toISOString()method of JS Date.
You can use
toJSDate() to get the Date object from a luxon DateTime:
const DateTime = luxon.DateTime; const dt = DateTime.now(); console.log(dt.toISO()) console.log(dt.toUTC().toISO()) console.log(dt.toJSDate().toISOString()) console.log(new Date().toISOString())