.Net中有个stopwatch非常方便,这里写个js的,简单用用
function
stopWatcher()
{
var timerRunning=false;
var startTime;
var endTime;
} ;
stopWatcher.prototype = {
start:function(){
this.startTime = new Date().getTime();
this.timerRunning=true;
},
stop:function(){
this.endTime = new Date().getTime();
this.timerRunning = false;
},
reset:function(){
this.startTime = null;
this.endTime = null;
this.timerRunning = false;
},
isRunning : function(){return this.timerRunning},
escapeTime :function(){return this.endTime - this.startTime}
}
var timerRunning=false;
var startTime;
var endTime;
} ;
stopWatcher.prototype = {
start:function(){
this.startTime = new Date().getTime();
this.timerRunning=true;
},
stop:function(){
this.endTime = new Date().getTime();
this.timerRunning = false;
},
reset:function(){
this.startTime = null;
this.endTime = null;
this.timerRunning = false;
},
isRunning : function(){return this.timerRunning},
escapeTime :function(){return this.endTime - this.startTime}
}