Javascript getTimezoneOffset 与时刻 utcOffset

标签 javascript date datetime momentjs

令我惊讶的是 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/

相关文章:

sql - 比较两个日期的提取年份

datetime - 如何将 DateTime::now() 转换为 NaiveDateTime?

c# - 将字符串解析为 DateTime 格式 "day, month dat, year"

mysql - 日期时间字符串到日期、输入时间和输出时间

c++ - 显示指定日期第二天的代码

javascript - 在 MongoDB 中按多个键排序

javascript - 使用 Web Worker 设置 Papa Parse 进度条

javascript - 如何获取前两个 URL 路径段?

javascript - 滑动句柄工具提示重叠时如何隐藏 div(显示 slider 范围)

php - 编辑 PHP 脚本的服务器时间