use locale "ia" with `Intl.DateTimeFormat` :
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const getOffset = (tz) => Intl.DateTimeFormat("ia", {
timeZoneName: "shortOffset",
timeZone : tz
})
.formatToParts()
.find((i) => i.type === "timeZoneName").value // => "GMT+/-hh:mm"
.slice(3); //=> +/-hh:mm
console.log('Asia/Dubai', ' UTC' + getOffset('Asia/Dubai'))
// to get your user timezone :
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
console.log(tz + ' UTC' + getOffset(tz))
<!-- end snippet -->
as mentioned by others, to get a timezone :
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
Not mentioned before, to get the offset from the timezone, use locale "ia" (see https://stackoverflow.com/a/64262840/1061871)
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
const getOffset = (tz) => Intl.DateTimeFormat("ia", {
timeZoneName: "shortOffset",
timeZone : tz
})
.formatToParts()
.find((i) => i.type === "timeZoneName").value // => "GMT+/-hh:mm"
.slice(3); //=> +/-hh:mm
console.log(tz + ' UTC' + getOffset(tz))
<!-- end snippet -->