Search the Community
Showing results for tags 'last update'.
-
Hi, I am new to html and css but I learned a thing or two through the tutorials. I am trying create a timer that indicates the last update of a post. So, the timer should count from 0 and stop when ever I update a new post. And, then, start the count again from 0. I was able to formulate one with the help of the tutorials, but I can't make it the way that I wanted. Instead, the timer automatically restarts when I refresh the page. Here's what I've made. I am not sure about the minutes and hours. <p id="p1">Last update: <label id="hours">00</label>:<label id="minutes">00</label>:<label id="seconds">00</label> <script type="text/javascript"> var hoursLabel = document.getElementById("hours"); var minutesLabel = document.getElementById("minutes"); var secondsLabel = document.getElementById("seconds"); var totalSeconds = 0; setInterval(setTime, 1000); function setTime() { ++totalSeconds; secondsLabel.innerHTML = pad(totalSeconds%60); minutesLabel.innerHTML = pad(parseInt(totalSeconds/60)); ++totalMinutes; minutesLabel.innerHTML = pad(totalMinutes%60); hoursLabel.innerHTML = pad(parseInt(totalMinutes/60)); ++totalHours; hoursLabel.innerHTML = pad(totalHours%24); hoursLabel.innerHTML = pad(parseInt(totalMinutes/60)); } function pad(val) { var valString = val + ""; if(valString.length < 2) { return "0" + valString; } else { return valString; } } </script></p> Could anyone help me out with how to make this not restart whenever the page is refreshed? I would really appreciate your help. Thanks.
- 13 replies