»
EnglishFrenchVietnamese

Print - Elapsed Time Calculator - JavaScriptBank.com

Full version: jsB@nk » Time » Counter » Elapsed Time Calculator
URL: https://www.javascriptbank.com/elapsed-time-calculator.html

Elapsed Time Calculator © JavaScriptBank.comThis script computes and displays the elapsed time between 'Start' and 'Finish' button clicks.

Full version: jsB@nk » Time » Counter » Elapsed Time Calculator
URL: https://www.javascriptbank.com/elapsed-time-calculator.html



JavaScript
<script language="Javascript"><!-- Gracefully hide from old browsers// Copyright © 2003 by David Tam, Ph.D. | http://www.ComputationalNeuralSystems.com//   You may copy, modify and/or distribute it under the terms of the GNU General Public License.//   See http://www.gnu.org/licenses/gpl.html for terms and conditions// Javascript to compute elapsed time between "Start" and "Finish" button clicksfunction timestamp_class(this_current_time, this_start_time, this_end_time, this_time_difference) { this.this_current_time = this_current_time;this.this_start_time = this_start_time;this.this_end_time = this_end_time;this.this_time_difference = this_time_difference;this.GetCurrentTime = GetCurrentTime;this.StartTiming = StartTiming;this.EndTiming = EndTiming;}//Get current time from date timestampfunction GetCurrentTime() {var my_current_timestamp;my_current_timestamp = new Date();//stamp current date & timereturn my_current_timestamp.getTime();}//Stamp current time as start time and reset display textboxfunction StartTiming() {this.this_start_time = GetCurrentTime();//stamp current timedocument.TimeDisplayForm.TimeDisplayBox.value = 0;//init textbox display to zero}//Stamp current time as stop time, compute elapsed time difference and display in textboxfunction EndTiming() {this.this_end_time = GetCurrentTime();//stamp current timethis.this_time_difference = (this.this_end_time - this.this_start_time) / 1000;//compute elapsed timedocument.TimeDisplayForm.TimeDisplayBox.value = this.this_time_difference;//set elapsed time in display box}var time_object = new timestamp_class(0, 0, 0, 0);//create new time object and initialize it//--></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form>  <input type="button" value="Start" onClick="time_object.StartTiming()"; name="StartButton">  <input type="button" value="Finish" onClick="time_object.EndTiming()"; name="EndButton">  </form>  <form name="TimeDisplayForm">  Elapsed time:  <input type="text" name="TimeDisplayBox" size="6">  seconds  </form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->