1

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?

AMATERASU
  • 63
  • 1
  • 5

1 Answers1

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