Categories
JavaScript Answers

How to get the exact local time of client with JavaScript?

Spread the love

Sometimes, we want to get the exact local time of client with JavaScript.

In this article, we’ll look at how to get the exact local time of client with JavaScript.

How to get the exact local time of client with JavaScript?

To get the exact local time of client with JavaScript, we use the Intl.DateTimeFormat constructor.

For instance, we write

const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;

to call resolvedOptions on the Intl.DateTimeFormat object to return an object with the client’s datetime options.

We get the time zone of the device with the timeZone property.

Conclusion

To get the exact local time of client with JavaScript, we use the Intl.DateTimeFormat constructor.

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 *