luxon convert local time to utc given a timezone
Since you know the timezone of you input date, you can use the zone
option when parsing it. As fromISO
docs states:
public static fromISO(text: string, opts: Object): DateTime
opts.zone
: use this zone if no offset is specified in the input string itself.
Then you can use toUTC
to convert your DateTime to UTC:
"Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
Equivalent to setZone('utc')
Here a live sample:
const DateTime = luxon.DateTime;
const d = DateTime.fromISO('2019-07-09T18:45', {zone: 'America/Chicago'});
console.log(d.toISO());
console.log(d.toUTC().toISO());
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.js"></script>
You can refer the following luxon function:
- isInDST https://moment.github.io/luxon/docs/class/src/datetime.js~DateTime.html#instance-get-isInDST
To check whether current time is based on DST or not!
- toUTC : function to convert to UTC based time
https://moment.github.io/luxon/docs/class/src/datetime.js~DateTime.html#instance-method-toUTC