92

I've created a tool in JavaScript that determines the current UTC time and checks if another predetermined date has passed yet.

I'd like to change my browser to another timezone and see if the tests still pass but I'm having trouble finding a way to do this.

Is there a way to do this in Chrome DevTools? If not, do any other suggestions come to mind?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
iPzard
  • 2,018
  • 2
  • 14
  • 24
  • 2
    See this https://stackoverflow.com/a/16449343/1225070 and this : https://stackoverflow.com/a/18612568/1225070 – Aefits Jun 14 '18 at 04:48
  • 4
    Chrome uses the timezone that comes from the operating system. So just go into your system preferences and change your timezone. – Barmar Jun 14 '18 at 06:03
  • Does this answer your question? [How to change local time zone in Chrome?](https://stackoverflow.com/questions/41667524/how-to-change-local-time-zone-in-chrome) – starball Jul 15 '23 at 19:03

4 Answers4

176

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

fernandopasik
  • 9,565
  • 7
  • 48
  • 55
  • 4
    Nice! And looks like you don't need to use a location in order to set the timezones, there's a "Timezone ID" there too, located under the latitude and longitude fields, I tested with US/Central, US/Easter, US/Pacific, and they all worked. Thanks! – iPzard Jan 31 '20 at 23:45
  • 1
    This is a great tip, thanks! I added my "custom" geolocation to the list, with the lat/long and timezone id from a google search. After that I can view logs and metrics etc.. all displayed with the required local timezone for the application. – David Thomas Feb 27 '20 at 06:39
  • 2
    Funny - it seems that it doesn't take daylight saving time into consideration. – Peter Jan 31 '21 at 05:16
  • 2
    Thank you so much, I can't believe I'm just now learning about this – Jackson Blankenship Jun 16 '21 at 19:34
  • @antoine129: yeah, best answer as a result of a [feature request I filed](https://bugs.chromium.org/p/chromium/issues/detail?id=993628), but received no credit for :) – Dan Dascalescu Dec 11 '21 at 21:26
16

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
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • 3
    What about Windows? How can I set this variable in application shortcut, the one I have on desktop? – izogfif Jun 18 '20 at 10:31
  • @izogfif Windows does not use environment variables to set the time zone; you can set "set TZ=…" in a bat file, but it has no effect for usual applications. – criticabug Apr 07 '21 at 13:47
1

July, 2023 Update:

On Chrome, press F12 to open Developer Tools:

enter image description here

Then, press Esc to open another panel which has Sensors tab:

enter image description here

Finally, selecting Location like Tokyo can set and change the browser timezone temporarily as shown below, then you can test a page by reloading the page:

enter image description here

If there isn't Sensors tab, you can open it from the 3 dots as shown below:

enter image description here

I use this function for testing internationally launched website.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

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

z0ccc
  • 31
  • 1
  • 3