Javascript getTimezoneOffset 与时刻 utcOffset
Javascript getTimezoneOffset vs moment utcOffset
令我惊讶的是 new Date().getTimezoneOffset()
returns 与 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.
接受的答案解释了 getTimezoneOffset
的作用,但 Moment.js 文档明确描述了时刻 utcOffset
和日期 getTimezoneOffset
之间的区别。
Note: Unlike moment.fn.zone this function returns the real offset from UTC, not the reverse offset (as returned by Date.prototype.getTimezoneOffset).
令我惊讶的是 new Date().getTimezoneOffset()
returns 与 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.
接受的答案解释了 getTimezoneOffset
的作用,但 Moment.js 文档明确描述了时刻 utcOffset
和日期 getTimezoneOffset
之间的区别。
Note: Unlike moment.fn.zone this function returns the real offset from UTC, not the reverse offset (as returned by Date.prototype.getTimezoneOffset).