This question already has an answer here:
这个问题在这里已有答案:
- How to use a custom time in browser to test for client vs server time difference 8 answers
如何在浏览器中使用自定义时间来测试客户端与服务器时差8个答案
I'm making a Javascript web application that depends on user's browser time zone.
我正在制作一个取决于用户浏览器时区的Javascript Web应用程序。
For example, whenever I check the UTC offset, I find it to be +5.5 only.
例如,每当我检查UTC偏移时,我发现它只是+5.5。
How do I test if it works in other time zones as well? I specially want to see how it works with US time zones.
如何测试它是否也适用于其他时区?我特别想看看它如何与美国时区一起使用。
I use Firefox mostly. Is there any configuration setting I can edit? I tried changing my system time zone, but it didn't work.
我主要使用Firefox。我可以编辑任何配置设置吗?我尝试更改系统时区,但它没有用。
2 个解决方案
#1
16
You need to restart your browser after you change your system's timezone. Firefox keeps the original timezone, I believe, and Chrome thinks you are in UTC if you do not restart.
更改系统的时区后,需要重新启动浏览器。我相信Firefox会保留原始时区,如果您不重启,Chrome会认为您使用的是UTC。
#2
6
In this regard, I've used this script on OS X: fresh-chrome-with-custom-tz.sh
在这方面,我在OS X上使用了这个脚本:fresh-chrome-with-custom-tz.sh
The script starts an instance of Chrome with its own environment. To configure it to use a specific timezone, edit this in the script:
该脚本启动具有自己环境的Chrome实例。要将其配置为使用特定时区,请在脚本中对其进行编辑:
# Change this to the spoof a different timezone. Helpful for testing timezone specific client facing content.
export TZ="America/Los_Angeles"
It relies on the TZ environment variable. Works like a charm!
它依赖于TZ环境变量。奇迹般有效!
#1
16
You need to restart your browser after you change your system's timezone. Firefox keeps the original timezone, I believe, and Chrome thinks you are in UTC if you do not restart.
更改系统的时区后,需要重新启动浏览器。我相信Firefox会保留原始时区,如果您不重启,Chrome会认为您使用的是UTC。
#2
6
In this regard, I've used this script on OS X: fresh-chrome-with-custom-tz.sh
在这方面,我在OS X上使用了这个脚本:fresh-chrome-with-custom-tz.sh
The script starts an instance of Chrome with its own environment. To configure it to use a specific timezone, edit this in the script:
该脚本启动具有自己环境的Chrome实例。要将其配置为使用特定时区,请在脚本中对其进行编辑:
# Change this to the spoof a different timezone. Helpful for testing timezone specific client facing content.
export TZ="America/Los_Angeles"
It relies on the TZ environment variable. Works like a charm!
它依赖于TZ环境变量。奇迹般有效!