Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?


1 Answers

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!