1

I need to create simple time counter until the register will be open.

I have create karate class that will be on each sunday at 13:00

Now i want to allow users to register to this class from 11:00

When the counter hits the time i set ( for example 11:00) the timer will disappear and some action will be (like register button will be show).

I need to get server time (it can be done by help from php).

var date = new Date("<?php echo date("Y-m-d H:i:s"); ?>");

Now i need help to create the time counter that will show hourse and minuts that left untile 11:00 form the server time (when user hit the webpage).

For example:

If the server time now is 10:42 the counter will show 18 minuts and 00 seconds left. and the counter will start counting time down.

user2413244
  • 231
  • 4
  • 16

1 Answers1

0

You may try this option, you can have a timer function as below:

function timer(till, onTimerElapsed) {
   var from = new Date();
   if (from < till){
      console.log(from);

      setTimeout(function() {
         timer(till, onTimerElapsed);
      }, 1000);  

      return false;
   }

   onTimerElapsed() 

   return true;       
}

You can invoke this on page load by passing the time (date) at which you want the timer to get elapsed. ex: to elapse the timer after 1 min from current time:

var till = new Date((new Date()).getTime() + 1000*60);
timer(till, function(){alert('timer elapsed');});

In place of alert in callback you can have the code to register.

Dhananjaya Kuppu
  • 1,322
  • 9
  • 10
  • You can copy and paste the timer() function in browser console window. Then copy and paste the next snippet that shows how to invoke timer, in console you will see datetime is printer every second and after 60 seconds it will throw alert. In case you have trouble, please let me know.. – Dhananjaya Kuppu May 09 '16 at 09:47