Skip to content

Instantly share code, notes, and snippets.

@shuding
Last active August 29, 2015 14:20
Show Gist options
  • Save shuding/72f99f6be888e790c3f2 to your computer and use it in GitHub Desktop.
Save shuding/72f99f6be888e790c3f2 to your computer and use it in GitHub Desktop.
A simple stopwatch script
var total = 0;
var startMoment = 0;
var timingInterval = null;
var displayTime = function (current) {
// console.log(current + total);
}
// start or continue
var startTiming = function () {
startMoment = (new Date()).getTime();
timingInterval = setInterval(function () {
displayTime((new Date()).getTime() - startMoment);
}, 10);
}
// stop or pause
var stopTiming = function () {
clearInterval(timingInterval);
total += (new Date()).getTime() - startMoment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment