Widget:CountdownStarPath
Jump to navigation
Jump to search
<script> (function() {
// Function to update the specific countdown to March 15, 2pm UTC function updateSpecificCountdown() { var currentDate = new Date(); var targetDate = new Date(Date.UTC(currentDate.getUTCFullYear(), 2, 15, 14, 0, 0)); // March 15, 2pm UTC
// If current date is past this year's target, move target to next year if (currentDate > targetDate) { targetDate.setUTCFullYear(currentDate.getUTCFullYear() + 1); }
var timeDifference = targetDate - currentDate;
var days = Math.floor(timeDifference / (24 * 60 * 60 * 1000)); var hours = Math.floor((timeDifference % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)); var minutes = Math.floor((timeDifference % (60 * 60 * 1000)) / (60 * 1000)); var seconds = Math.floor((timeDifference % (60 * 1000)) / 1000);
var countdownText = ;
if (timeDifference <= 24 * 60 * 60 * 1000) { // Format as H:MM:SS for the last 24 hours countdownText = hours + ':' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2); } else { // Else, format as Xd Xh Xm for more than 24 hours countdownText = days + 'd ' + hours + 'h ' + minutes + 'm'; }
document.getElementById('countdown-specific').innerHTML = countdownText;
// Use a separate setTimeout to avoid clashing with other scripts setTimeout(updateSpecificCountdown, 1000); }
// Ensure this does not conflict with window.onload used by other scripts if (window.addEventListener) { window.addEventListener('load', updateSpecificCountdown, false); } else if (window.attachEvent) { window.attachEvent('onload', updateSpecificCountdown); } else { document.addEventListener('DOMContentLoaded', updateSpecificCountdown, false); }
})(); </script>