Skip to content

Instantly share code, notes, and snippets.

@v1dhun
Created September 27, 2021 11:33
Show Gist options
  • Save v1dhun/1e2c4a43ffdee0afbac2d75dd6546b7a to your computer and use it in GitHub Desktop.
Save v1dhun/1e2c4a43ffdee0afbac2d75dd6546b7a to your computer and use it in GitHub Desktop.

Revisions

  1. v1dhun created this gist Sep 27, 2021.
    22 changes: 22 additions & 0 deletions time.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <!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>