// Library for timing things in JavaScript function Timer() { // member properties this.startTime = new Date(); this.endTime = new Date(); // member methods // reset the start time to now this.start = function () { this.startTime = new Date(); } // reset the end time to now this.stop = function () { this.endTime = new Date(); } // get the difference in milliseconds between start and stop this.getTime = function () { return (this.endTime.getTime() - this.startTime.getTime()) / 1000; } // get the current elapsed time from start to now, this sets the endTime this.getElapsed = function () { this.endTime = new Date(); return this.getTime(); } }