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.