How to get Australia Sydney timezone offset in javascript nodejs

0 votes
Austalia/Sydney timezone offset (UTC to AEST difference) is +10:00 (from April first Sunday) and +11:00 (from April first Sunday) (from October first Sunday).

There is a 600 minute or 660 minute difference.

In javascript/nodejs/momentjs, how can I retrieve the time difference? Regardless of server time?
Jun 14 in Node-js by Vaani
• 7,020 points
46 views

1 answer to this question.

0 votes

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)}`);
}
answered Jun 14 by Neha
• 8,560 points

Related Questions In Node-js

0 votes
1 answer

How to get the _id of inserted document in Mongo database in NodeJS?

Hello @kartik, A shorter way than using second ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,740 points
8,405 views
0 votes
1 answer

How to get path from the request in nodejs?

Hello @kartik, Try this out: var http = require('http'); var ...READ MORE

answered Oct 14, 2020 in Node-js by Niroj
• 82,740 points
2,330 views
0 votes
1 answer

How to get GET (query string) variables in Express.js on Node.js?

Hello @kartik, Since you've mentioned Express.js in your ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,740 points
1,947 views
0 votes
1 answer

How to get access to webpack-dev-server from devices in local network?

Hello @kartik, You can set your ip address ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,740 points
3,778 views
0 votes
0 answers

No US HAWAII time zone in Momentjs or nodejs

How can I use Momentjs to adjust ...READ MORE

Jun 23 in Node-js by Vaani
• 7,020 points
19 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,000 views
0 votes
1 answer
0 votes
1 answer

How to use pino-transport in nodejs for logs?

Ensure that you have a recent version ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,560 points
198 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP