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.
Display Time based on TimeZone
<!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