Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *