Source code:
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Dynamic Clock</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: radial-gradient(circle, #1e3c72, #2a5298);
color: #fff;
font-family: ‘Arial’, sans-serif;
overflow: hidden;
}
.clock {
position: relative;
width: 200px;
height: 200px;
}
.clock .circle {
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
border: 5px solid rgba(255, 255, 255, 0.2);
}
.clock .circle:before {
content: ”;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
border: 0px solid transparent;
border-top: 5px solid #4dd0e1;
animation: rotateSeconds 60s linear infinite;
}
.clock .time {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.clock .time h1 {
font-size: 2.5rem;
margin: 0;
}
.clock .time p {
font-size: 1rem;
margin: 5px 0 0;
letter-spacing: 1px;
color: rgba(255, 255, 255, 0.7);
}
@keyframes rotateSeconds {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class=”clock”>
<div class=”circle”></div>
<div class=”time”>
<h1 id=”time”>00:00:00</h1>
<p id=”date”>Jan 01, 2025</p>
</div>
</div>
<script>
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, ‘0’);
const minutes = String(now.getMinutes()).padStart(2, ‘0’);
const seconds = String(now.getSeconds()).padStart(2, ‘0’);
const timeString = `${hours}:${minutes}:${seconds}`;
const dateOptions = { year: ‘numeric’, month: ‘short’, day: ‘2-digit’ };
const dateString = now.toLocaleDateString(undefined, dateOptions);
document.getElementById(‘time’).textContent = timeString;
document.getElementById(‘date’).textContent = dateString;
}
setInterval(updateClock, 1000);
updateClock(); // Initialize immediately
</script>
</body>
</html>