Home / Widgets / Simple Countdown Timer
Duplicate Snippet

Embed Snippet on Your Site

Simple Countdown Timer

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

100+
Code Preview
html
<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";
            }
        }
        setInterval(function() { countdownTimer(); }, 1000);
</script>

Comments

Add a Comment