I need a Javascript function that given a timezone, returns the current UTC offset.
For example, theFuncIneed('US/Eastern') -> 240
It has become possible nowaday with Intl API:
The implementation of Intl is based on icu4c. If you dig the source code, you'll find that timezone name differs per locale, for example:
for (const locale of ["ja", "en", "fr"]) {
  const timeZoneName = Intl.DateTimeFormat(locale, {
    timeZoneName: "short",
    timeZone: "Asia/Tokyo",
  })
    .formatToParts()
    .find((i) => i.type === "timeZoneName").value;
  console.log(timeZoneName);
}Fortunately, there is a locale, Interlingua (the langauge tag is ia), which uses the same pattern (ex. GMT+11:00) for timezone names.
The snippet below can meed your need:
const getOffset = (timeZone) => {
  const timeZoneName = Intl.DateTimeFormat("ia", {
    timeZoneName: "short",
    timeZone,
  })
    .formatToParts()
    .find((i) => i.type === "timeZoneName").value;
  const offset = timeZoneName.slice(3);
  if (!offset) return 0;
  const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
  if (!matchData) throw `cannot parse timezone name: ${timeZoneName}`;
  const [, sign, hour, minute] = matchData;
  let result = parseInt(hour) * 60;
  if (sign === "+") result *= -1;
  if (minute) result += parseInt(minute);
  return result;
};
console.log(getOffset("US/Eastern")); // 240
console.log(getOffset("Atlantic/Reykjavik")); // 0
console.log(getOffset("Asia/Tokyo")); // -540This way can be a little tricky but it works well in my production project. I hope it helps you too :)
Many thanks to Bort for pointing out the typo. I have corrected the snippet.
if (minute) result + parseInt(minute);. Should that be +=?0 for console.log(getOffset("US/Eastern"));timeZoneName: "short", to timeZoneName: "shortOffset", seems to fix this snippet so it works in Chrome 100, Firefox 99, and Node 18. I haven't tested other browsers or node versions. Otherwise, specifying a timezone of "US/Eastern" returns a timeZoneName of "EDT" which does not contain a parseable GMT offset.if (minute) result += parseInt(minute); first and then if (sign === "+") result *= -1; Otherwise all the timezone offsets which have minutes are calculated incorrectly. For example, Asia/Calcutta offset is 5.5 meaning it should be -330 but your code gives -270.In general, this is not possible.
US/Eastern is an identifier for a time zone.  (It's actually an alias to America/New_York, which is the real identifier.)
240 is a time zone offset.  It's more commonly written as -04:00  (Invert the sign, divide by 60).
The US Eastern Time Zone is comprised of both Eastern Standard Time, which has the offset of -05:00 and Eastern Daylight Time, which has the offset of -04:00.
So it is not at all accurate to say US/Eastern = 240.  Please read the timezone tag wiki, especially the section titled "Time Zone != Offset".
Now you did ask for the current offset, which is possible. If you supply a date+time reference, then you can resolve this.
For the local time zone of the computer where the javascript code is executing, this is built in with .getTimezoneOffset() from any instance of a Date object.
But if you want it for a specific time zone, then you will need to use one of the libraries I listed here.
UTC - localTime expressed in minutes. So I think it's reasonable in a javascript forum to write +240 where -04:00 might otherwise be used..getTimeZoneOffset() should be .getTimezoneOffset() without the uppercase ZFollowing function can be used to return the UTC offset given a timezone:
const getTimezoneOffset = (timeZone, date = new Date()) => {
  const tz = date.toLocaleString("en", {timeZone, timeStyle: "long"}).split(" ").slice(-1)[0];
  const dateString = date.toString();
  const offset = Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);
  
  // return UTC offset in millis
  return offset;
}
It can be used like:
const offset = getTimezoneOffset("Europe/London");
console.log(offset);
// expected output => 3600000
Date.parse(`${dateString} ${tz}`) - Date.parse(`${dateString} UTC`);. Otherwise, it won't align with the built-in Date.prototype.getTimezoneOffset."Europe/London" should be 0timeZoneNameNaN for me.You can do this using moment.js
moment.tz('timezone name').utcOffset()
Although this involves using moment-timezone.js
This is a shorter version that should work with all modern browser and Node.js versions, and with all locale settings, as the step that requires parsing of a date string uses the date time string format, which is universally supported. (Making use of the fact that the format used for the locale 'sv' differs only by using a space instead of a 'T' and does not include a time zone name unless requested.)
function getTimeZoneOffset(date, timeZone) {
  const toTimeZone = z => new Date(date.toLocaleString('sv', { timeZone: z }).replace(' ', 'T'));
  return (toTimeZone(timeZone) - toTimeZone('UTC')) / 60_000;
}
The function will return the offset that was or will be in effect for the specified IANA time zone name at the time of the supplied date.
Example with DST is in effect in most of Europe, as well as in North America
getTimeZoneOffset(new Date('2025-10-01'), 'Europe/London'): 60
getTimeZoneOffset(new Date('2025-10-01'), 'America/New_York'): -240
Different DST status in Europe and North America, respectively
getTimeZoneOffset(new Date('2025-11-01'), 'Europe/London'): 0
getTimeZoneOffset(new Date('2025-11-01'), 'America/New_York'): -240
No DST in either region
getTimeZoneOffset(new Date('2025-11-10'), 'Europe/London'): 0
getTimeZoneOffset(new Date('2025-11-10'), 'America/New_York'): -300
The answer of @ranjan_purbey results in NaN for me and the answer of @Weihang Jian throws an exception in Chrome (but works in Firefox).
Therefore, based on all the answers I came up with the following function which is basically a combination of both answers working together successfully for me:
function getTimeZoneOffset(timeZone) {
    const date = new Date().toLocaleString('en', {timeZone, timeZoneName: 'short'}).split(' ');
    const timeZoneName = date[date.length - 1];
    const offset = timeZoneName.slice(3);
    if (!offset) {
      return 0;
    }
    const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
    if (!matchData) {
      throw new Error(`Cannot parse timezone name: ${timeZoneName}`);
    }
    const [, sign, hour, minute] = matchData;
    let result = parseInt(hour, 10) * 60;
    if (sign === '+') {
      result *= -1;
    }
    if (minute) {
      result += parseInt(minute, 10);
    }
    return result;
}
zone()method.US/Easternwill be recognized by all implementations.