Countdown Timer

Display a countdown timer using this snippet anywhere on your site.

<div id="countdown"></div>

<script>
    function countdownTimer() {
        var endTime = new Date("December 31, 2025 23:59:59").getTime();
        var now = new Date().getTime();
        var timeLeft = endTime - now;

        var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
        var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);

        document.getElementById('countdown').innerHTML = days + "d " + hours + "h " +
            minutes + "m " + seconds + "s ";

        if (timeLeft < 0) {
            clearInterval(x);
            document.getElementById('countdown').innerHTML = "EXPIRED";
        }
    }

    var x = setInterval(countdownTimer, 1000);
</script>

Post Comment