Take the start of this year:
var start = new Date(2011, 0, 1);
Calculate how much time has passed:
var elapsed = new Date() - start;
Say your bet is $ 1 in 10 seconds:
var rate = 1 / 10 / 1000;
Calculate how many containers have been handled since the beginning of this year:
var cans = Math.floor(elapsed * rate);
Thus, a simple setup can be:
var start = new Date(2011, 0, 1);
var rate = 1 / 10 / 1000;
var base = 50000000;
setInterval(function () {
var cans = Math.floor((new Date() - start) * rate) + base;
$("#cans").text(cans);
}, 5000);
http://jsfiddle.net/eKDXB/
Optimization may be to maintain the refresh interval according to a known speed, but it is probably best to keep your presentation updates untied from the speed information.
source
share