如何为Visual Studio和浏览器设置时区 [英] How to set time zone for Visual Studio and browser

查看:317
本文介绍了如何为Visual Studio和浏览器设置时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2015社区版。有什么方法可以在一个时区中运行Visual Studio,而在另一个时区中运行浏览器吗?可以说我想在CST时区运行浏览器,在UTC时区运行Visual Studio

I am using visual studio 2015 Community edition. Is there any way to run visual studio in one timezone and browser in other time zone? Lets say i want to run browser in CST time zone and Visual Studio in UTC time zone

这是我到目前为止尝试过的(未成功)

Here is what i have tried so far ( unsuccessfully )

让我们说Visual Studio在当前用户下执行

Lets say visual studio executes under current user

方法1>设置当前用户的时区到CST。启动浏览器。然后将当前用户TimeZone更改为UTC并以调试模式启动VS。我希望浏览器在启动时将时区缓存为CST,但事实并非如此。

Method 1> Set current user's time zone to CST. Start the browser. Then Change current user TimeZone to UTC and Start VS in debugging mode. I was hoping browser will cache the time zone as CST when it was started, but that is not the case.

方法2>创建一个 new用户在本地计算机上。将其时区设置为CST,将当前用户的时区设置为UTC。使用新用户的其他用户启动浏览器。并以当前用户身份在调试模式下启动VS

Method 2> Create a new user on local machine. Set its time zone to CST and set current user's time zone to UTC. Start the browser using different user as new user. And start VS in debugging mode as current user

这两种方法均无效。我正在使用的浏览器是IE和Chrome

Both methods did not work. The browsers i am using are IE and Chrome

推荐答案

在Windows上更改时区会在整个系统范围内进行更改。您不能在一个时区运行App A,而在另一个时区运行App B。

Changing the time zone on Windows changes it system-wide. You cannot have app A run in one time zone and app B run in another.

有一些例外情况:


  • 某些程序是使用POSIX C API编写的,这些API寻找 TZ 环境变量。虽然此方法在Linux / OSX上可以正常工作,但不幸的是,该方法在Windows上存在问题,因此不应依赖。

  • Some programs are written using POSIX C APIs, which look for the TZ environment variable. While this works reasonably well on Linux/OSX, unfortunately this approach is buggy on Windows and should not be relied upon.

某些程序会读取系统时区一次启动后,在应用程序的整个生命周期中都坚持使用它。许多网络浏览器使用来执行此操作,但是随后人们报告了当它们从一个时区移至另一个时区并且浏览器未正确更新时的错误,并且此后的行为得到了解决。因此,Windows上的大多数网络浏览器现在都在监听 WM_TIMECHANGE 消息,该消息会在时间或时区更新时触发。

Some programs will read the system time zone once on startup and then hold on to it for the lifetime of the application. Many web browsers used to do this, but then people reported bugs when they moved from one time zone to another and the browser didn't update correctly, and such behavior was subsequently fixed. So most web browser on Windows now listen for WM_TIMECHANGE messages, which fire whenever the time or time zone are updated.

因此,总的来说,没有-无法完成您所要求的。如果要测试网站在不同时区的行为,则需要使用多台计算机。一种方法是在虚拟机中运行Web浏览器,因为您可以更改VM的时区,而又不影响主机的时区。

So in general, no - there's no way to accomplish what you asked for. If you are trying to test how your web site behaves in different time zones, you will need to use more than one computer. One approach is to run the web browser in a virtual machine, as you can change the time zone of the VM without it affecting the host computer's time zone.

在Linux上运行测试。您可以将 TZ 环境变量设置为任何有效的 IANA时区ID ,并且您可以为每个进程设置不同的环境变量。

Alternatively, consider running your tests on Linux. You can set the TZ environment variable to any valid IANA time zone ID, and you can set environment variables differently per process.

这篇关于如何为Visual Studio和浏览器设置时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆