I haven't done any study to find out whether there is a "better" method to accomplish this, but then why would I?
This function was written in a matter of minutes using Intl.DateTimeFormat
Modern browsers and nodejs are supported.
function getTZoffset(timeZone, d, m, y) {
const date = Date.UTC(y, m - 1, d, 0, 0, 0);
const tgt = Intl.DateTimeFormat('en', { timeZone, dateStyle: "short", timeStyle: 'short', hour12: false }).format(date).split(',');
const utc = Intl.DateTimeFormat('en', { timeZone: 'UTC', dateStyle: "short" }).format(date).split(',');
const tgtTimes = tgt[1].split(':').map(Number);
const tgtTime = (tgtTimes[0] % 24) * 60 + tgtTimes[1]
const utcTime = tgt[0] === utc[0] ? 0 : 24 * 60;
return tgtTime - utcTime;
}
for (let m = 1; m <= 12; m++) {
console.log(`Sydney/Australia 1/${m}/2020: ${getTZoffset('Australia/Sydney', 1, m, 2020)}`);
}
for (let m = 1; m <= 12; m++) {
console.log(`America/New_York 1/${m}/2020: ${getTZoffset('America/New_York', 1, m, 2020)}`);
}