timer
by jimkennelly
HTML
<script src="//www.addressfinder.co.nz/assets/v2/widget.js"></script>
<table>
<tr><td>Start: </td><td><label class="CallStart"></label></td></tr>
<tr><td>Call: </td><td><label class="CallTimer"></label></td></tr>
</table>
CSS
body {
padding: 5px;
}
label {
font-weight: bold;
}
input[type=text] {
width: 20em
}
p {
margin: 1em 0 0;
}
JavaScript
$(document).ready(function() {
var now = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var start = (h<10?'0'+h:h) + ':' + (m<10?'0'+m:m) + ':' + ( s<10?'0'+s:s);
$('.CallStart').text(start);
var start = new Date;
$('.Timer').text('00:00');
setInterval(function() {
var t= (new Date - start) / 1000;
t=parseInt(t,10);
var tHours = parseInt(t/3600,10);
var tMinutes = parseInt((t-tHours)/60,10);
var tSeconds = t-tMinutes *60;
console.log(tSeconds);
var tElapsed = ( tHours<101? '0' + tHours : tHours) + ':' + ( tMinutes<101? '0' + tMinutes : tMinutes) + ':' + (tSeconds<10? '0' + tSeconds : tSeconds);
$('.CallTimer').text(tElapsed);
}, 1000);
});