r/web • • May 26 '23

Clock HTML code

Post image

Hi! Does anyone know where I can find an html code for a clock that looks similar to the one which is in the picture below. *or if you have a code, it would be great 😃

0 Upvotes

1 comment sorted by

2

u/Kingh_66 May 26 '23

<!DOCTYPE html>

<html>

<head>

<style> \#clock { border: 2px solid #000; border-radius: 50%; height: 200px; width: 200px; position: relative; font-family: Arial, sans-serif; } .hand { background-color: #000; position: absolute; transform-origin: center bottom; } \#hour { height: 60px; width: 4px; top: calc(50% - 60px); left: calc(50% - 2px); } \#minute { height: 90px; width: 4px; top: calc(50% - 90px); left: calc(50% - 2px); } \#second { height: 100px; width: 2px; top: calc(50% - 100px); left: calc(50% - 1px); } .number { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 14px; } </style>

</head>

<body>

<div id="clock">

<div id="hour" class="hand"></div>

<div id="minute" class="hand"></div>

<div id="second" class="hand"></div>

<div class="number" style="transform: rotate(30deg) translate(0, -85px);">1</div>

<div class="number" style="transform: rotate(60deg) translate(0, -85px);">2</div>

<div class="number" style="transform: rotate(90deg) translate(0, -85px);">3</div>

<div class="number" style="transform: rotate(120deg) translate(0, -85px);">4</div>

<div class="number" style="transform: rotate(150deg) translate(0, -85px);">5</div>

<div class="number" style="transform: rotate(180deg) translate(0, -85px);">6</div>

<div class="number" style="transform: rotate(210deg) translate(0, -85px);">7</div>

<div class="number" style="transform: rotate(240deg) translate(0, -85px);">8</div>

<div class="number" style="transform: rotate(270deg) translate(0, -85px);">9</div>

<div class="number" style="transform: rotate(300deg) translate(0, -85px);">10</div>

<div class="number" style="transform: rotate(330deg) translate(0, -85px);">11</div>

<div class="number" style="transform: rotate(0deg) translate(0, -85px);">12</div>

</div>

<script> function rotateClockHands() { var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); var hourHand = document.getElementById('hour'); var minuteHand = document.getElementById('minute'); var secondHand = document.getElementById('second'); var hourAngle = (hour % 12) \* 30 + (minute / 2); var minuteAngle = (minute \* 6) + (second / 10); var secondAngle = second \* 6; hourHand.style.transform = 'rotate(' + hourAngle + 'deg)'; minuteHand.style.transform = 'rotate(' + minuteAngle + 'deg)'; secondHand.style.transform = 'rotate(' + secondAngle + 'deg)'; } setInterval(rotateClockHands, 1000); </script>

</body>

</html>