Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get timezone RAW Offset? Node.JS

When you go to https://worldtimeapi.org/api/timezone/Europe/Berlin it says raw_offset=3600 , i’m trying to get this value in Node.JS. Need help please, i’m giving my code below but it’s giving me wrong output

const moment = require("moment-timezone");
let timezone = "Europe/Warsaw";
let haha = moment().tz(timezone);
let timezone_raw = haha.utcOffset()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Doesn’t look wrong they just use a different format.
Worldtime-API seems to use seconds where moment.js seems to use minutes.
According to my test moment.js also returns 60 from utcOffset().

You can either take the raw_offset and divide it by 60 (seconds per minute) to get 60 (minutes).
Or you can take the return from utcOffset() and multiply it by 60 to get 3600.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading