有没有办法在 Chrome devtools 中改变你的时区?

我已经用 JavaScript 创建了一个工具,用于确定当前的 UTC 时间,并检查另一个预先确定的日期是否已经过去。

我想改变我的浏览器到另一个时区,看看是否测试仍然通过,但我有麻烦找到一个办法这样做。

在 Chrome 开发工具中有这样做的方法吗? 如果没有,还有其他的建议吗?

70952 次浏览

2020 update: see the other answer, which shows the result of a feature request I filed with Chromium to implement a way to override the timezone.

Note that the technique only works to change the location (including timezone) in that tab. Other tabs will still use the system's timezone. DevTools isn't a reliable way to spoof your timezone.

To change the timezone for all tabs in the browser (Chrome or Firefox or whatever), on Linux/MacOS, you can launch the browser with the TZ environment variable set to the desired timezone name:

TZ=America/New_York chromium-browser

To do this in Chrome Dev tools you can use the Geolocation sensor emulation. Go to the 3 dotted menu, More Tools and Sensors.

There's a Geolocation dropdown with some common locations but you can change your preferred one as well. To do that you can choose Other... in that dropdown and enter a custom Timezone ID

Here's a demo page to test it: https://mathiasbynens.be/demo/timezone and a video that shows the procedure: https://www.youtube.com/watch?v=pIpN_AuV4AI

Timezone testing in Chrome developer tools

You can also do this with the Vytal extension which uses the devtool location sensor emulation. It can spoof your timezone, locale, geolocation and user agent. You can also automatically set your location data to match your ip address.

https://chrome.google.com/webstore/detail/vytal-spoof-timezone-loca/ncbknoohfjmcfneopnfkapmkblaenokb?utm_source=4