Public Code Page
New Year's Countdown Code
Below is the code snippet displayed as readable text:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Year's Countdown</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background: #000;
}
#countdown-container {
margin-top: 50px;
color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(255, 255, 255, 0.5);
display: inline-block;
font-size: 24px;
font-weight: bold;
}
#countdown {
font-size: 48px;
margin-top: 10px;
}
</style>
</head>
<body>
<div id="countdown-container">
<div>Time Until New Year:</div>
<div id="countdown">Loading...</div>
</div>
<script>
function updateCountdown() {
const now = new Date();
const nextYear = now.getFullYear() + 1;
const newYear = new Date(`January 1, ${nextYear} 00:00:00`).getTime();
const timeLeft = newYear - now.getTime();
if (timeLeft > 0) {
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
document.getElementById("countdown").textContent =
`${days}d ${hours}h ${minutes}m ${seconds}s`;
} else {
document.getElementById("countdown").textContent = "Happy New Year!";
}
}
// Update the countdown every second
setInterval(updateCountdown, 1000);
updateCountdown(); // Call immediately to avoid initial delay
</script>
</body>
</html>