How to detect browser time zone on client side with JavaScript?

Sometimes, we want to detect browser time zone on client side with JavaScript.

In this article, we’ll look at how to detect browser time zone on client side with JavaScript.

How to detect browser time zone on client side with JavaScript?

To detect browser time zone on client side with JavaScript, we can use the Internationalization API.

For instance, we write:

console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)

to use Intl.DateTimeFormat().resolvedOptions().timeZone to get the time zone from the browser the device is running on.

Therefore, if we’re in the Pacific time zone, we see 'America/Los_Angeles' logged.

Conclusion

To detect browser time zone on client side with JavaScript, we can use the Internationalization API.