Created
September 27, 2021 11:33
-
-
Save v1dhun/1e2c4a43ffdee0afbac2d75dd6546b7a to your computer and use it in GitHub Desktop.
Display Time based on TimeZone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> | |
| </head> | |
| <body> | |
| <script> | |
| const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; | |
| var time | |
| const xhttp = new XMLHttpRequest(); | |
| xhttp.onload = function() { | |
| const today = new Date(JSON.parse(this.responseText).datetime) | |
| time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds() | |
| print() | |
| } | |
| xhttp.open("GET", `http://worldtimeapi.org/api/timezone/${timezone}`); // https://worldtimeapi.org/pages/examples | |
| xhttp.send(); | |
| function print(){ | |
| document.write(time) | |
| } | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment