Untitled

 avatar
unknown
html
a year ago
1.6 kB
12
Indexable


        .countdown {
            font-size: 2em;
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

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

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            // Hedef tarih ve saat (yıl, ay, gün, saat, dakika, saniye)
            const targetDate = new Date('2024-01-01T00:00:00');

            function updateCountdown() {
                const currentDate = new Date();
                const timeDifference = targetDate - currentDate;

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

                const countdownElement = document.getElementById('countdown');
                countdownElement.innerHTML = `${days} gün ${hours} saat ${minutes} dakika ${seconds} saniye`;

                // Geri sayım tamamlandığında isteğe bağlı olarak başka bir şey yapabilirsiniz.
                // Örneğin: countdownElement.innerHTML = "Geri sayım tamamlandı!";
            }

            // İlk çağrı
            updateCountdown();

            // Her saniye güncellenmesi için bir interval oluşturun
            setInterval(updateCountdown, 1000);
        });
    </script>
Editor is loading...
Leave a Comment