function findNextWeekday(date, weekday, time) {
var newDate = new Date(date.getTime());
newDate.setDate(date.getDate() + (7 + weekday - date.getDay()) % 7);
newDate.setHours(time, 0, 0, 0);
return newDate;
}
var targetDate = findNextWeekday(new Date(), 5, 15);
// Update the countdown every second
var updateCountdown = setInterval(function() {
// Get current date and time
var currentTime = new Date().getTime();
// Calculate the difference between current time and target time
var timeDifference = targetDate - currentTime;
// Calculate days, hours, minutes, seconds
var days = Math.floor(timeDifference / (1000 * 60 * 60 * 24)).toString();
var hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString();
var minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60)).toString();
var seconds = Math.floor((timeDifference % (1000 * 60)) / 1000).toString();
// Display the countdown in specific elements
document.getElementById("circle-days").innerHTML = days + "<div class='timer-font'>Days</div>";
document.getElementById("circle-hours").innerHTML = hours + "<div class='timer-font'>Hours</div>";
document.getElementById("circle-minutes").innerHTML = minutes + "<div class='timer-font'>Minutes</div>";
document.getElementById("circle-seconds").innerHTML = seconds + "<div class='timer-font'>Seconds</div>";
// If countdown is over, display message
if (timeDifference < 0) {
clearInterval(updateCountdown);
document.getElementById("timer").innerHTML = "Selecting Winners...";
}
}, 1000);
* {
margin: 0;
padding: 0;
width: 100%;
}
body {
background-color: transparent;
}
.wrapper {
display: flex;
gap: 10%;
align-items: center;
justify-content: center;
}
.container {
color: transparent;
margin: 0 auto;
text-align: center;
}
.circle-time {
color: #FE7030;
font-size: 60px;
font-family: "Roboto Slab", Helvetica, Arial, sans-serif;
font-weight: bold;
text-align: center;
}
.timer-font {
font-family: "Roboto Slab", Helvetica, Arial, sans-serif;
font-weight: bold;
color: #027B46;
font-size: 25px;
}
span {
text-align: center;
}
<div class="wrapper">
<span style="margin-right: 20px;">
<span id="circle-days" class="circle-time"></span>
</span>
<span style="margin-right: 20px;">
<span id="circle-hours" class="circle-time"></span>
</span>
<span style="margin-right: 20px;">
<span id="circle-minutes" class="circle-time"></span>
</span>
<span id="circle-seconds" class="circle-time"></span> <span id="timer"></span>
</div>