Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript PHP Good countdown timer
    text
    copied!<p>Basically I'm any good at javascript and I would like a better countdown timer for my project. At the moment my timer looks something like this:</p> <blockquote> <p>01:25:05</p> </blockquote> <p>I would like it to look like this:</p> <blockquote> <p>1 hour, 25 minutes and 5 seconds</p> </blockquote> <p>But I also want it to be clever. So if its just 25 minutes it will say:</p> <blockquote> <p>25 minutes.</p> </blockquote> <hr> <p>This is my current javascript code:</p> <pre><code>function secondCountdown(){ if(typeof(skip) == "undefined"){ skip = "set"; } else { var timeleft = document.getElementById("timeleft").innerHTML; var time_split = timeleft.split(":"); if(parseInt(time_split[0]) &lt; 10){ time_split[0] = time_split[0].charAt(1); } if(parseInt(time_split[1]) &lt; 10){ time_split[1] = time_split[1].charAt(1); } if(parseInt(time_split[2]) &lt; 10){ time_split[2] = time_split[2].charAt(1); } seconds = parseInt(time_split[2]) + parseInt(time_split[1]*60) + parseInt(time_split[0]*3600); seconds -= 1; if(seconds &gt; 0){ var hours= Math.floor(seconds/3600); seconds %= 3600; var minutes = Math.floor(seconds/60); seconds %= 60; var timeleft = ((hours &lt; 10) ? "0" : "") + hours + ":" + ((minutes &lt; 10) ? "0" : "") + minutes + ":" + ((seconds &lt; 10) ? "0" : "") + seconds; document.getElementById("timeleft").innerHTML = timeleft; } else { document.getElementById("timeleft").innerHTML = ""; window.location='test.php?pageid=' + getURLParam("pageid"); return false; } } setTimeout("secondCountdown()",1000); } window.onload = secondCountdown; </code></pre> <p>Maybe someone could edit it for me to make it output what I want?</p> <p>Edit:</p> <p>This is the PHP side of the timer.</p> <pre><code>&lt;span id="timeleft"&gt; $master = $timer['gta_time'] - time(); echo date( "00:i:s", $timer['gta_time'] - time() ); &lt;/span&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload