Countdown to Sunday service

Published by

on

// Function to update the countdown function updateCountdown() { // Set the target time to Sunday 10:00 AM UK time const targetTime = new Date(); targetTime.setUTCHours(10, 0, 0, 0); targetTime.setDate(targetTime.getDate() + (7 – targetTime.getUTCDay())); // Current time const now = new Date(); // Calculate the time difference let timeDiff = targetTime – now; // If the target time is in the past, set it to next Sunday if (timeDiff < 0) { targetTime.setDate(targetTime.getDate() + 7); timeDiff = targetTime – now; } // Calculate hours, minutes, and seconds const hours = Math.floor(timeDiff / (1000 * 60 * 60)); const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000); // Display the countdown document.getElementById('countdown').innerHTML = 'Countdown: ' + hours + 'h ' + minutes + 'm ' + seconds + 's'; // If it's Sunday 10:00 AM, display a different message if (hours === 0 && minutes === 0 && seconds === 0) { document.getElementById('countdown').innerHTML = 'It\'s now till 1:00 PM'; } } // Update the countdown every second setInterval(updateCountdown, 1000); // Initial update updateCountdown();

Leave a comment