JavaScript Time Library
Several weeks ago I spent some time working with JavaScript for a separate project, and I needed some “stopwatch” functionality. I was shocked to find there were no good, simple classes to fit my needs. Moreover — there were awful examples for javascript time functions out there (like never-ending loop, to name the worst). So, I spent some time to write my own. And then, I just needed some more time to repack what I wrote as a useful small library. The result is already here: my JavaScript Time Library. There are no big things in this library — just a stopwatch and backward clock “classes” and some support functions. Still — it should be piece of cake for anyone to include this library in any javascript project (download and quick guide on the JavaScript Time library pages).
Example Usage
It’s simple as creating an object and firing the timer:
|
1 2 3 4 5 6 7 8 9 10 11 |
var stopWatch = new jtl.stopWatch(); ... /* executed on "start" link clicked: */ function start(){ if(stopWatch.start()!=null){ stopWatch.executeOnRefresh(refresh); //function to execute on refresh var value= stopWatch.splittime(); $('#timer').find('.value').text(toTime(value)); $('#split_times').html(''); } } |
For more info — give a try to the examples and help info here.
Cheers!