Skip to content

Instantly share code, notes, and snippets.

@jomasero
Created June 26, 2013 16:23
Show Gist options
  • Save jomasero/5868899 to your computer and use it in GitHub Desktop.
Save jomasero/5868899 to your computer and use it in GitHub Desktop.
Contador de tiempo en página web.
<!DOCTYPE html>
<html>
<head>
<script>
var startday = new Date();
var clockStart = startday.getTime();
function initStopwatch()
{
var myTime = new Date();
return((myTime.getTime() - clockStart) / 1000);
}
function getSecs()
{
var tSecs = Math.round(initStopwatch());
var iSecs = tSecs % 60;
var iMins = Math.round((tSecs-30)/60);
var sSecs ="" + ((iSecs > 9) ? iSecs : "0" + iSecs);
var sMins ="" + ((iMins > 9) ? iMins : "0" + iMins);
document.forms[0].timespent.value = sMins+":"+sSecs;
window.setTimeout('getSecs()',1000);
}
</script>
</head>
<body onload="window.setTimeout('getSecs()', 1)">
<form>
<input size="5" name="timespent" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment