I am trying to create a clock based on time. It is not based on current_dates. The initial time to be pulled will be from a separate php file. This will be for a game based browser. When someone clicks a button to run this script. it checks if certain requirements are met, and if so, this script will be triggered. Based on the level of the object, it will pull out the start timer for that level. Hope this makes sense. Anyway, I based the script timer on the first code that I provide.
This script only takes minutes and seconds into account. I changed it to include days and hours. Somewhere in this process, I got confused, and the script doesn't work at all. I'm also not quite sure if this is the best method to calculate this. So, if you have a cleaner method at the same time, please share. Thank you in advance.
This script is based on the minutes / seconds script I saw. Here's the original source:
<span id="countdown" class="timer"></span> <script> var seconds = 60; function secondPassed() { var minutes = Math.round((seconds - 30)/60); var remainingSeconds = seconds % 60; if (remainingSeconds < 10) { remainingSeconds = "0" + remainingSeconds; } document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds; if (seconds == 0) { clearInterval(countdownTimer); document.getElementById('countdown').innerHTML = "Buzz Buzz"; } else { seconds--; } } var countdownTimer = setInterval('secondPassed()', 1000); </script>
Here is a modified script that I am trying to include in days, hours, minutes and seconds.
<span id="countdown"></span> <script> var current_level = 93578; function timer() { var days = Math.round(current_level/86400); var remainingDays = Math.round(current_level - (days * 86400)); if (days <= 0){ days = current_level; } var hours = Math.round(remainingDays/3600); var remainingHours = Math.round(remainingDays - (hours * 3600)); if (hours >= 24){ hours = 23; } var minutes = Math.round(remainingHours/60); var remainingMinutes = Math.round(remainingHours - (minutes * 60)); if (minutes >= 60) { minutes = 59; } var seconds = Math.round(remainingMinutes/60); document.getElementById('countdown').innerHTML = days + ":" + hours ":" + minutes + ":" + seconds; if (seconds == 0) { clearInterval(countdownTimer); document.getElementById('countdown').innerHTML = "Completed"; } } var countdownTimer = setInterval('timer()', 1000); </script>
javascript php timer countdowntimer
Phoenix ryan
source share