为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

new Date().getTimezoneOffset() returns wrong time zone offset against Firefox ESR 52

  • 9 个回答
  • 7 人有此问题
  • 13 次查看
  • 最后回复者为 Sunny12345

more options

I tried to use "new Date().getTimezoneOffset()" in a javascript to return the timezone offset between the time zone on my PC and UTC time.

The time zone on my PC is UTC+8,

Javascript as below, referring to https://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript

var offset = new Date().getTimezoneOffset(); console.log(offset);

It returns -60 mins. This is wrong.

Could you please advise the cause and resolution if there is?

Regards,

Sunny

I tried to use "new Date().getTimezoneOffset()" in a javascript to return the timezone offset between the time zone on my PC and UTC time. The time zone on my PC is UTC+8, Javascript as below, referring to https://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript var offset = new Date().getTimezoneOffset(); console.log(offset); It returns -60 mins. This is wrong. Could you please advise the cause and resolution if there is? Regards, Sunny

所有回复 (9)

more options

Additional info. I've tried: reinstall and ESR 45.x and change time zone several times. getTimezoneOffset() always returns -60mins.

more options

What does this code give?

  • new Date().toString();
more options

I'm in Pacific Time. Firefox 54 returns 420, which I believe means 7 hours. Since we are at -7 hours (year-round offset of -8 hours adjusted for DST), I'm not sure why 420 is a positive number.

Is your Firefox "sandboxed" in any way, such that it may not be directly reading the time from Windows 7?

more options

Thanks for the reply.

new. Date().toString() returns a result indicates the wrong time zone GMT+1, as below, "Thu Aug 03 2017 02:39:03 GMT+0100"

more options

Thanks and please fine below answer.

jscher2000 said

I'm in Pacific Time. Firefox 54 returns 420, which I believe means 7 hours. Since we are at -7 hours (year-round offset of -8 hours adjusted for DST), I'm not sure why 420 is a positive number. =>what is the time zone setting on your PC? UTC-7? Is your Firefox "sandboxed" in any way, such that it may not be directly reading the time from Windows 7? I reinstalled Firefox ESR many times and the issue persists, i did not change the browser settings. How can i know if the firefox is sandboxed or not?
more options

Please note that the browser in question is Firefox ESR.

Firefox non ESR has no such issue.

If you install the latest Firefox, you can easily reproduce the issue i believe.

Thanks.

more options

Sunny12345 said

Thanks and please fine below answer. jscher2000 said
I'm in Pacific Time. Firefox 54 returns 420, which I believe means 7 hours. Since we are at -7 hours (year-round offset of -8 hours adjusted for DST), I'm not sure why 420 is a positive number.

=>what is the time zone setting on your PC? UTC-7?

Time Zone is -8, with automatic adjustment for Daylight Savings Time. (Screenshot attached.)

Is your Firefox "sandboxed" in any way, such that it may not be directly reading the time from Windows 7?

I reinstalled Firefox ESR many times and the issue persists, i did not change the browser settings.

How can i know if the firefox is sandboxed or not?

I don't use ESR, sorry. Firefox could be sandboxed by security software or by a virtual machine program (e.g., VirtualBox). Probably you would notice other symptoms such as limitations on Firefox's ability to work with the hard drive or interact with other programs.

more options

This looks like UK time.

What Firefox locale do you have (about:config -> general.useragent.locale)?

more options

Thank you! the locale is set to locale. please refer to the attachment.