- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Detect User Timezone in JavaScript?
To detect the user timezone with the name of the timzone itself, use the Internationalization API. This gives the name of the Timezone in which the user and the browser is being worked on.
Detect Exact Timezone with Name
Example
To get the exact timezone name, we will use the Internationalization API −
<!DOCTYPE html> <html> <body> <h1>Timezone</h1> <p id="test"></p> <script> document.getElementById("test").innerHTML = Intl.DateTimeFormat().resolvedOptions().timeZone; </script> </body> </html>
Output
![](https://www.tutorialspoint.com/assets/questions/media/123055-1666263058.png)
Get the Timezone (Difference between UTC and local time)
Example
To get the timezone, use the getTimezoneOffset() in JavaScript. This method returns the time difference between UTC time and local time. The difference returned is in minutes.
<!DOCTYPE html> <html> <body> <h1>Timezone</h1> <p id="test"></p> <script> const dt = new Date(); let diffTZ = dt.getTimezoneOffset(); document.getElementById("test").innerHTML = diffTZ; </script> </body> </html>
Output
![](https://www.tutorialspoint.com/assets/questions/media/123055-1666263080.png)
Advertisements