gpt4 book ai didi

javascript - date.getTimezoneOffset() 未返回预期值

转载 作者:行者123 更新时间:2023-11-30 16:28:52 27 4
gpt4 key购买 nike

我的浏览器在东部标准时区运行,当我调用 date.getTimezoneOffset() 时,我希望返回 -300,但我得到的是 300

var date = new Date();
date.getTimezoneOffset();
// returns 300

最佳答案

来自 the Mozilla docs (或 devdocs.io ):

Return value
The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead. For example, if your time zone is UTC+10 (Australian Eastern Standard Time), -600 will be returned. Daylight saving time prevents this value from being a constant even for a given locale.

EST 落后于 UTC,因此您得到了一个积极的结果。

我同意这不是表示它的好方法 - 我更习惯于将偏移量称为“您添加到 UTC 以获得本地时间的时间量”,但它至少表现得如文档所示...

关于javascript - date.getTimezoneOffset() 未返回预期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33659991/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com