How to get the offset time when the timezone is known using moment.js?

Is there a way to know the offset time (how much ahead or behind the UTC/GMT), if I have the timezone value (for example 'America/Chicago') in momentjs or some other library in javascript?

1 answer

  • answered 2021-07-27 18:27 Mr. Polywhirl

    You can grab the utcOffset.

    const offset = moment().tz('America/Chicago').utcOffset();
    console.log(`Offset in hours: ${offset / 60}`);
    <script src=""></script>
    <script src=""></script>

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum