問題描述
我注意到,對于我們在東部時區(America/New_York"),時區偏移為 -05:00" Date.getTimezoneOffset() 返回一個正 300 的數量.我預計在 Utc 以西的地區以分鐘為單位的偏移量為負數,在 Utc 以東的地區為正數,但顯然它是翻轉的".這個決定背后的原因是什么?
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/ 遵循相同的規則并返回...
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
同時 DateTimePicker http://trentrichardson.com/examples/timepicker/ 在設置它的時候不會翻轉數字初始時區"參數.錯了嗎?
At the same time DateTimePicker http://trentrichardson.com/examples/timepicker/ does not flip numbers when setting its initial 'timezone' parameter. Is it wrong?
推薦答案
因為它是這樣定義的.引用文檔(MDN):
Because that's how it's defined. Quoting the doc (MDN):
時區偏移量是 UTC 和當地時間.請注意,這意味著 偏移量是正的,如果本地時區落后于 UTC,如果領先則為負數.
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.
這篇關于為什么 JavaScript Date.getTimezoneOffset() 會考慮“-05:00"?作為一個積極的抵消?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!