Created
January 30, 2024 14:09
-
-
Save mnako/840103d3e0b2c6b3f8a8bd18df8f635d to your computer and use it in GitHub Desktop.
This file contains 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> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<style> | |
html, body { | |
background-color: rgb(39, 39, 42); | |
} | |
body, h2, p { | |
margin: 0; | |
padding: 0; | |
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; | |
} | |
.container { | |
position: relative; | |
text-align: left; | |
color: #4f4f4f; | |
width: 100vw; | |
height: 100vh; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
flex-direction: column; | |
} | |
.container h2 { | |
padding: 2rem; | |
font-size: 2rem; | |
color: rgb(244, 244, 245); | |
} | |
.container h2 small { | |
font-size: .875rem; | |
background-clip: text; | |
background-image: linear-gradient(to right, rgb(236, 72, 153), rgb(168, 85, 247), rgb(59, 130, 246)); | |
color: transparent; | |
text-transform: uppercase; | |
} | |
@media only screen and (min-width: 768px) { | |
.container { | |
flex-direction: row; | |
} | |
.container h2 { | |
padding: 3rem; | |
font-size: 3rem; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h2 data-locale="Warsaw" data-offset="1"> | |
<p></p> | |
<small>Warsaw, Poland</small> | |
</h2> | |
<h2 data-locale="Hanoi" data-offset="7"> | |
<p></p> | |
<small>Hanoi, Vietnam</small> | |
</h2> | |
<h2 data-locale="Tokyo" data-offset="9"> | |
<p></p> | |
<small>Tokyo, Japan</small> | |
</h2> | |
</div> | |
<script> | |
function searchClocks() { | |
document.querySelectorAll(".container h2").forEach(item => { | |
const timezone = { | |
locale: item.getAttribute("data-locale"), | |
offset: item.getAttribute("data-offset") | |
}; | |
item.querySelector("p").innerHTML = calcTime(timezone); | |
setInterval(() => { | |
item.querySelector("p").innerHTML = calcTime(timezone); | |
}, 1000); | |
}); | |
} | |
function calcTime(timezone) { | |
const d = new Date(), | |
utc = d.getTime() + (d.getTimezoneOffset() * 60000), | |
nd = new Date(utc + (3600000 * timezone.offset)); | |
return nd.toLocaleDateString(undefined, { | |
hourCycle: "h24", | |
year: "numeric", | |
month: "short", | |
day: "numeric", | |
weekday: "short", | |
hour: "numeric", | |
minute: "numeric" | |
}); | |
} | |
searchClocks(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment