How To Create Countdown Timer dynamically using php and javascript. Your countdown will start on the page load. You can use your online exam system and many other places.
<p id="demo" style="text-align: center;font-size: 45px;margin-top: 0px;"></p>
<?php
$examMin=1;
$start = date('Y-m-d H:i:s');
$nowdateM=date('Y-m-d H:i:s',strtotime('+0 hour +'.$examMin.' minutes',strtotime($start)));
$nowdate=strtotime($nowdateM);
$m=date('M',$nowdate);
$d=date('d',$nowdate);
$y=date('Y',$nowdate);
$time=date("H:i:s",$nowdate);
?>
<script>
var countDownDate = new Date("<?php echo $m; ?> <?php echo $d; ?>,<?php echo $y; ?> <?php echo $time; ?>").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
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);
document.getElementById("demo").innerHTML = minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !