
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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

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

Advertisements