Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 536
vkelman Avatar asked Jan 13 '14 22:01

vkelman


People also ask

Why is getTimezoneOffset negative?

The number of minutes returned by getTimezoneOffset() is positive if the local time zone is behind UTC, and negative if the local time zone is ahead of UTC.

What is getTimezoneOffset in JavaScript?

getTimezoneOffset() returns the difference between UTC time and local time. getTimezoneOffset() returns the difference in minutes. For example, if your time zone is GMT+2, -120 will be returned.

What is offset in timestamp?

What is a "zone offset"? A zone offset is the difference in hours and minutes between a particular time zone and UTC. In ISO 8601, the particular zone offset can be indicated in a date or time value. The zone offset can be Z for UTC or it can be a value "+" or "-" from UTC.

How do you read timezone offset?

A common way to express a zone offset in field-based formats is with +/- followed by the offset. So for example, Japan is 9 hours ahead of UTC, so you may see a time written as 2016-06-11 05:10+09:00 .


1 Answers

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.

like image 113
raina77ow Avatar answered Oct 02 '22 09:10

raina77ow