Last active
August 29, 2015 14:20
-
-
Save shuding/72f99f6be888e790c3f2 to your computer and use it in GitHub Desktop.
A simple stopwatch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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