Javascript 如何针对不同的时区测试我的浏览器时区相关应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4976696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I test my browser timezone dependent application againts different timezones?
提问by kapeels
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。是否有任何我可以编辑的配置设置?我尝试更改系统时区,但没有用。
回答by Ben Belchak
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。
回答by facundofarias
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 环境变量。奇迹般有效!