Clock using html+css+js

Prince - Sep 18 - - Dev Community

HTML CODE

 <div class="clock">
        <div class="clock-face">
            <div class="hand hour-hand"></div>
            <div class="hand minute-hand"></div>
            <div class="hand second-hand"></div>
        </div>
        <div class="digital-time" id="digital-time"></div>
    </div>
Enter fullscreen mode Exit fullscreen mode

CSS CODE

 body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #282c34;
    color: white;
    font-family: 'Arial', sans-serif;
}

.clock {
    margin-top: 30%;
    display: flex;
    flex-direction: column;

}

.clock-face {
    width: 300px;
    height: 300px;
    background-color: #282c34;
    border-radius: 50%;
    position: relative;
    transform: translateY(-50%);

    box-shadow: 0 0 40px 1px purple; /* Added a blurred box-shadow */
}


.hand {
    width: 36%;
    height: 6px;
    background: #58f5db;
    position: absolute;
    top: 50%;
    left:10%;
    transform-origin: 100%;
    transform: rotate(90deg);
    transition-timing-function: ease-in-out;
    transition: all 0.05s;
}

.hour-hand {
    height: 3px;

    background-color:white
}
.minute-hand{
    height: 5px;

    background-color:white;
}
.second-hand{
    height: 3px;
    background-color: purple;
}

.digital-time {
    text-align: center;
    font-size:larger;
    font-weight: bolder;
    box-shadow: 0 0 20px 4px purple;
    padding:5px

}
Enter fullscreen mode Exit fullscreen mode

JAVASCRIPT CODE

   const hourHand = document.querySelector('.hour-hand');
const minuteHand = document.querySelector('.minute-hand');
const secondHand = document.querySelector('.second-hand');
const digitalTime = document.getElementById('digital-time');

function setClock() {
    const now = new Date();
    const seconds = now.getSeconds();
    const minutes = now.getMinutes();
    const hours = now.getHours();

    const secondsDegrees = ((seconds / 60) * 360) + 90;
    const minutesDegrees = ((minutes / 60) * 360) + ((seconds / 60) * 6) + 90;
    const hoursDegrees = ((hours / 12) * 360) + ((minutes / 60) * 30) + 90;

    secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
    minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
    hourHand.style.transform = `rotate(${hoursDegrees}deg)`;

    // Digital time display
    digitalTime.innerHTML = now.toLocaleTimeString();
}

setInterval(setClock, 1000);
setClock(); // Initial call to set the clock immediately

Enter fullscreen mode Exit fullscreen mode
. . . . . . . .
Terabox Video Player