28 September 2021

How to create event time(Timmer) in PHP and Javascript?

Create event time(Timmer) in PHP and Javascript.


<?php 
/* date_default_timezone_set('Asia/Calcutta');
$timestamp = time(); */
//set hours according to the India time

$date = '2021-09-28';
$hour = '13';
$minutes = '14';
$seconds = '0';

?>
<div id="timer"></div>
<script>

//task: get timer details from the previous section and assign them to variables. 
//tip, these are associative arrays accessed as $myArray['data'] 

const countDownDate = <?php 


 echo strtotime("$date $hour:$minutes:$seconds" ) ?> * 1000;

let timeNow = <?php print(time()) ?> * 1000;

// Every second, the countdown will be updated.

let i = setInterval(function() {

 timeNow = timeNow + 1000;

// Calculate the time between now and the end of the countdown.  

let dist = countDownDate - timeNow;

// Calculate the number of days, hours, minutes, and seconds in days, hours, minutes, and seconds.

let numOfDays = Math.floor(dist / (1000 * 60 * 60 * 24));

let hr = Math.floor((dist % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

let min = Math.floor((dist % (1000 * 60 * 60)) / (1000 * 60));

let sec = Math.floor((dist % (1000 * 60)) / 1000);

// Put the result in an element with the id="timer" attribute.  

document.getElementById("timer").innerHTML = numOfDays + "d " + hr + "h " +

min + "m " + sec + "s ";

// When the countdown is over, type some text. 

if (dist < 0) {

clearInterval(i);

document.getElementById("timer").innerHTML = "TIMER EXPIRED";

}

}, 1000);

</script>

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...