gpt4 book ai didi

Javascript getTimezoneOffset 与时刻 utcOffset

转载 作者:行者123 更新时间:2023-11-28 15:16:04 24 4
gpt4 key购买 nike

令我惊讶的是 new Date().getTimezoneOffset() 返回与 moment().utcOffset() 相反的内容

示例:

  • 时区 UTC +08:00 香港
    • JS:-480
    • 时刻:480
  • 时区 UTC -06:00 中美洲
    • JS:360
    • 时刻:-360
  • 时区 UTC 伦敦
    • JS:0
    • 时刻:-0

问题:
如果我是正确的,momentjs 将返回正确的值。那么为什么 Javascript new Date().getTimezoneOffset() 返回相反的时区偏移量呢?

最佳答案

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.

来自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

关于Javascript getTimezoneOffset 与时刻 utcOffset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33890898/

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