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="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data.min.js"></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