Firefox 不会在 Windows 上读取本地时间

Firefox does not read local time on Windows

本文关键字:读取 时间 Windows Firefox      更新时间:2023-09-26

我在使用MomentJS库时发现了Windows上的Firefox中的一个错误。但是,这似乎是Firefox Date()本身中的一个错误。

问题在于使用 getTimezoneOffset() 函数以及其他本地时间函数(如 getHours() 函数)获取本地时间。它在 Windows 上根本不会获得本地时间偏移量。其他浏览器,包括OSX上相同版本的Firefox,获得正确的时间。

这是我的设置:

OSX:10.10.5

  • 铬:48.0.2564.82
  • 火狐浏览器:43.0.4

视窗: 7, SP1, 最新的更新

  • 铬:48.0.2564.82
  • IE浏览器 11.0.9.9600.18163
  • 火狐浏览器:43.0.4

OSX:

  • 铬:

    new Date() 
    # Thu Jan 21 2016 10:07:23 GMT-0700 (MST)
    new Date().getTimezoneOffset()
    # 420 (minutes, correct)
    new Date().getHours()
    # 10 (this is correct, since I am -07:00 UTC)
    
  • 火狐:

    new Date() 
    # Date 2016-01-21T17:03:49.807Z
    new Date().getTimezoneOffset()
    # 420 (minutes, correct)
    new Date().getHours()
    # 10 (correct)
    

窗户:

  • 铬:

    new Date() 
    # Thu Jan 21 2016 10:10:41 GMT-0700 (MST)
    new Date().getTimezoneOffset()
    # 420 (minutes, correct)
    new Date().getHours()
    # 10 (correct)
    
  • IE浏览器:

    new Date() 
    # Thu Jan 21 2016 10:16:09 GMT-0700 (MST)
    new Date().getTimezoneOffset()
    # 420 (minutes, correct)
    new Date().getHours()
    # 10 (correct)
    
  • 火狐:

    new Date() 
    # Date 2016-01-21T17:12:43.807Z
    new Date().getTimezoneOffset()
    # 0 (INCORRECT)
    new Date().getHours()
    # 17 (INCORRECT - No timezone offset)
    

据我所知,这只是Windows上Firefox中的一个错误。这是对的吗?我对该功能(和其他本地时区功能)应该如何工作有任何误解吗?

事实证明,Firefox 会在 Windows 上查找TZ环境变量,并尝试使用它来设置本地时区。我找到了这个旧的Mozilla错误报告,它帮助我弄清楚了这一点。

我们为服务器端应用程序使用 TZ 环境变量。我重命名了变量,现在一切都按预期工作。