Search code examples
javascriptluxon

Create a luxon DateTime while keeping the original timezone offset


If I have the following ISO date:

2021-07-05T13:20:00+06:00

If I call DateTime.FromISO it will convert it to machine local time, I then have to parse the string and set the zone manually.

How do I create a luxon DateTime object with the offset of +06:00 as in the parsed string without the extra work?

Please note, I know I can use DateTime.fromISO(isoDate, { zone: 'utc' }); or any other zone, but do I have to really parse the iso string and get the zone manually to pass it to the {zone: } option?


Solution

  • I found it:

    const date = DateTime.fromISO("2021-07-05T13:20:00+06:00", { setZone: true });
    

    the setZone: true option will take care of that.