<!DOCTYPE html>
<html>
<body>
 
<h2>JavaScript abc</h2>
 
<p id="demo"></p>
<button onclick="zmacknutoA()">START</button> 
<button onclick="zmacknutoB()">STOP</button>
 
<script>
 
function zmacknutoA(){
a = new Date()
}
 
function zmacknutoB(){
b = new Date()
document.getElementById('demo').innerHTML = 
 (b-a)/1000 + "s"
}
 
</script>
 
</body>
</html>

Opakování

<!DOCTYPE html>
<html>
<body>
 
<h2>JavaScript abc</h2>
 
<p id="demo"></p>
<button onclick="zmacknutoA()">START</button> 
<button onclick="zmacknutoB()">STOP</button>
 
<script>
 
function zmacknutoA(){
a = new Date()
}
 
function zmacknutoB(){
b = new Date()
document.getElementById('demo').innerHTML = 
 (b-a)/1000 + "s"
 a=null
}
 
function update(){
if(a){
  b = new Date()
document.getElementById('demo').innerHTML = 
 (b-a)/1000 + "s"
 }
}
setInterval(update, 20)
 
</script>
 
</body>
</html>