英文:
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 the wrong output.
const moment = require("moment-timezone");
let timezone = "Europe/Warsaw";
let haha = moment().tz(timezone);
let timezone_raw = haha.utcOffset();
英文:
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()
</details>
# 答案1
**得分**: 0
看起来并没有错,只是它们使用不同的格式。
Worldtime-API 似乎使用秒,而 moment.js 似乎使用分钟。
根据我的测试,moment.js 也从 `utcOffset()` 返回 60。
您可以将 `raw_offset` 除以 60(每分钟的秒数)得到 60(分钟)。
或者您可以取 `utcOffset()` 的返回值,乘以 60 得到 3600。
<details>
<summary>英文:</summary>
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.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论