Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript getTimezoneOffset vs moment utcOffset

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?

like image 669
hwcverwe Avatar asked Dec 28 '25 04:12

hwcverwe


1 Answers

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.

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

like image 126
shahkalpesh Avatar answered Dec 30 '25 18:12

shahkalpesh