Why does JavaScript Date.getTimezoneOffset() consider "-05:00" as a positive offset?

vkelman picture vkelman · Jan 13, 2014 · Viewed 28.4k times · Source

I noticed that for us on Eastern Time zone ("America/New_York") with timezone offset of "-05:00" Date.getTimezoneOffset() returns a positive number of 300. I would expect offset in minutes to be negative in areas to the West from Utc, and to be positive in areas to the east of Utc, but apparently it's "flippded". What's the reasoning behind that decision?

http://momentjs.com/ follows the same rule and returns...

moment.parseZone("01/13/2014 3:38:00 PM +01:00").zone()   // == -60
moment.parseZone("01/13/2014 3:38:00 PM -01:00").zone()   // == 60

At the same time DateTimePicker http://trentrichardson.com/examples/timepicker/ does not flip numbers when setting its initial 'timezone' parameter. Is it wrong?

Answer

raina77ow picture raina77ow · Jan 13, 2014

Because that's how it's defined. Quoting the doc (MDN):

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.