// Set the date we're counting down to // 1. JavaScript // var countDownDate = new Date("Sep 5, 2018 15:37:25").getTime(); // 2. PHP var countDownDate = 1555231440 * 1000; var now = 1714245998 * 1000; if(document.getElementById("timer") != null){ // Update the count down every 1 second var x = setInterval(function() { // Get todays date and time // 1. JavaScript // var now = new Date().getTime(); // 2. PHP now = now + 1000; // Find the distance between now an the count down date var distance = ( countDownDate - now ) - 1000; //custom deduct 1ms to match with current time on display. // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Output the result in an element with id="timer" if (days > 0){ document.getElementById("timer").innerHTML = "倒数 " + days + "d " + hours + "h " + minutes + "m " + seconds + "s "; } else if ( days == 0 && hours > 0){ document.getElementById("timer").innerHTML = "倒数 " + hours + "h " + minutes + "m " + seconds + "s "; } else if ( days == 0 && hours == 0 && minutes > 0){ document.getElementById("timer").innerHTML = "倒数 " + minutes + "m " + seconds + "s "; } else { document.getElementById("timer").innerHTML = "倒数 " + seconds + "s "; } // If the count down is over, write some text // If the cound down is over, replace the text into a link with image if (distance < 0) { clearInterval(x); document.getElementById("timer").innerHTML = ""; document.getElementById("countdown-button").style.display = "block"; } }, 1000); }