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?
Asked
Active
Viewed 883 times
1 Answers
1
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>

Mr. Polywhirl
- 42,981
- 12
- 84
- 132