I was surprised that new Date().getTimezoneOffset()
returns the opposite of moment().utcOffset()
Examples:
- Timezone UTC +08:00 Hong Kong
- JS: -480
- Moment: 480
- Timezone UTC -06:00 Central America
- JS: 360
- Moment: -360
- Timezone UTC London
- JS: 0
- Moment: -0
Question:
If I am correct momentjs is returning the correct value. So why is Javascript new Date().getTimezoneOffset()
returning the opposite timezone offset?
I was surprised that new Date().getTimezoneOffset()
returns the opposite of moment().utcOffset()
Examples:
- Timezone UTC +08:00 Hong Kong
- JS: -480
- Moment: 480
- Timezone UTC -06:00 Central America
- JS: 360
- Moment: -360
- Timezone UTC London
- JS: 0
- Moment: -0
Question:
If I am correct momentjs is returning the correct value. So why is Javascript new Date().getTimezoneOffset()
returning the opposite timezone offset?
2 Answers
Reset to default 5The 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.
from: https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
The accepted answer explains what getTimezoneOffset
does but Moment.js docs explicitly describe the difference between moment utcOffset
and the date getTimezoneOffset
.
Note: Unlike moment.fn.zone this function returns the real offset from UTC, not the reverse offset (as returned by Date.prototype.getTimezoneOffset).
Source: https://momentjs./docs/#/manipulating/utc-offset/