Preferably in php, but can be in javascript too and please pass the time values to a variable in php, as it will have an input to register the time leading to another page in php to register in the database.
Thank you in advance.
Preferably in php, but can be in javascript too and please pass the time values to a variable in php, as it will have an input to register the time leading to another page in php to register in the database.
Thank you in advance.
In php I think it's not what you want, since it runs on server.
I made a simple code in pure Javascript. Example working on Fiddle:
But I do not know if you want a stopwatch or if you want a countdown timer.
function formatatempo(segs) {
min = 0;
hr = 0;
/*
if hr < 10 then hr = "0"&hr
if min < 10 then min = "0"&min
if segs < 10 then segs = "0"&segs
*/
while(segs>=60) {
if (segs >=60) {
segs = segs-60;
min = min+1;
}
}
while(min>=60) {
if (min >=60) {
min = min-60;
hr = hr+1;
}
}
if (hr < 10) {hr = "0"+hr}
if (min < 10) {min = "0"+min}
if (segs < 10) {segs = "0"+segs}
fin = hr+":"+min+":"+segs
return fin;
}
var segundos = 0; //inicio do cronometro
function conta() {
segundos++;
document.getElementById("counter").innerHTML = formatatempo(segundos);
}
function inicia(){
interval = setInterval("conta();",1000);
}
function para(){
clearInterval(interval);
}
function zera(){
clearInterval(interval);
segundos = 0;
document.getElementById("counter").innerHTML = formatatempo(segundos);
}
<span id="counter">00:00:00</span><br>
<input type="button" value="Parar" onclick="para();"> <input type="button" value="Iniciar" onclick="inicia();"> <input type="button" value="Zerar" onclick="zera();">