Jump to content

Need a bit of help with the countdown timer.

Recommended Posts

Here's the code for the countdown timer. It works. At the end of the countdown, it's suppose to show the message "EXPIRED". But that message only shows once I reload the page. The countdown itself stops at 00:00:01. Is there a way to automatically show the message after that, instead of reloading the page to show it?

      margin: 100px auto;
      width: 305px;
      border:1px solid #000000;
  div#counter span{
      background-color: #00CAF6;

  $target_date = '2019-01-12 05:40:00';
  $timeLeft = (strtotime($target_date) - time()) * 1000;
<script src="javascripts/timer.js"></script>

      var timeLeft = <?php echo $timeLeft ; ?>;
      var timer =  new Timer($('#counter'), timeLeft);
      if (timeLeft <= 0) {

<div id="counter">
  <span class="hour">00</span>
  <span class="min">00</span>
  <span class="sec">00</span>


Edited by imgrooot

Share this post

Link to post
Share on other sites

Personally I wouldn't use a counter: it's vulnerable to drift since each interval won't fire exactly every 1.000 seconds.

Use Date to get the current timestamp and diff it with the start timestamp (which you also got from Date).

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.