本文介绍了date.getTimezoneOffset()未返回期望值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的浏览器在东部标准时区运行,当我打电话给date.getTimezoneOffset()时,我希望返回-300却得到300
My browser is running in the Eastern Standard Timezone, when call I call date.getTimezoneOffset() I expect -300 to be returned but instead I get 300
var date = new Date();
date.getTimezoneOffset();
// returns 300
推荐答案
从(或):
EST是 behind UTC ,因此您得到了积极的结果。
EST is behind UTC, therefore you're getting a positive result.
我同意这不是代表它的好方法-我更习惯于抵消时间添加到UTC以获取本地时间,但至少表现得如所记载...
I agree it's not a great way to represent it - I'm much more used to an offset being "the amount of time you add to UTC to get local time" but it is at least behaving as documented...
这篇关于date.getTimezoneOffset()未返回期望值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!