Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating time difference

Status
Not open for further replies.

Stecochan

MIS
Joined
Sep 13, 2011
Messages
1
Location
CH
Hi,

I am new to this forum and have recently started to explore Javascript functionality to create little 'programs' to help me with my hobby as a private pilot.

One of the applications I have in mind simply makes a timestamp of different flight phases when the pilot presses the relevant button (before taxi, before takeoff, after landing and after stopping the engine).

Below I've include the code I got to so far. I haven't been able to calculate the time difference and to show that value automatically when the second value is available (e.g. block time = blocks on - blocks off; flight time = landing - takeoff).

I'd be grateful if anyone could help!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
<meta name="viewport" content="width=device-width; initial-scale=1.4; maximum-scale=1.4; user-scalable=0;">
<meta name = "format-detection" content = "telephone=no">
<META NAME="Googlebot" CONTENT="noindex">
<title>TimeStamper</title>

<script type="text/javascript">


function BlocksOff(TimeStamp1) {
Time_Blocks_Off = new Date().toUTCString();
TimeStamp1.TimeBlocksOff.value = Time_Blocks_Off;
}

function TakeOff(TimeStamp2) {
Time_TakeOff = new Date().toUTCString();
TimeStamp2.TimeTakeOff.value = Time_TakeOff;
}

function Landing(TimeStamp3) {
Time_Landing = new Date().toUTCString();
TimeStamp3.TimeLanding.value = Time_Landing;
}

function BlocksOn(TimeStamp4) {
Time_Blocks_On = new Date().toUTCString();
TimeStamp4.TimeBlocksOn.value = Time_Blocks_On;
TimeResult1.BlockTime.value = ( Time_Blocks_Off - Time_Blocks_On );
}


--></SCRIPT>
<html>
<head>
<TITLE>TimeStamper</TITLE>
</head>
<body BGCOLOR="#FFFFFF">



<FORM NAME="TimeStamp1">
<TABLE>
<TR> <TD align="center"> <INPUT TYPE="TEL" style="text-align: center" NAME="TimeBlocksOff" SIZE="35"></TD>
<TD align="center"> <INPUT TYPE="BUTTON" NAME="Submit" VALUE="Blocks off" ONCLICK="BlocksOff(this.form)"> </TD> </TR>
</TABLE>
</FORM>

<br />

<FORM NAME="TimeStamp2">
<TABLE>
<TR> <TD align="center"> <INPUT TYPE="TEL" style="text-align: center" NAME="TimeTakeOff" SIZE="35"> </TD>
<TD align="center"> <INPUT TYPE="BUTTON" NAME="Submit" VALUE="Takeoff" ONCLICK="TakeOff(this.form)"> </TD> </TR>
</TABLE>
</FORM>

<br />

<FORM NAME="TimeStamp3">
<TABLE>
<TR> <TD align="center"> <INPUT TYPE="TEL" style="text-align: center" NAME="TimeLanding" SIZE="35"></TD>
<TD align="center"> <INPUT TYPE="BUTTON" NAME="Submit" VALUE="Landing" ONCLICK="Landing(this.form)"> </TD> </TR>
</TABLE>
</FORM>

<br />

<FORM NAME="TimeStamp4">
<TABLE>
<TR> <TD align="center"> <INPUT TYPE="TEL" style="text-align: center" NAME="TimeBlocksOn" SIZE="35"></TD>
<TD align="center"> <INPUT TYPE="BUTTON" NAME="Submit" VALUE="Blocks on" ONCLICK="BlocksOn(this.form)"> </TD> </TR>
</TABLE>
</FORM>

<br />

<FORM NAME="TimeResult1">
<TABLE>
<TR> <TD align="center"> <INPUT TYPE="BUTTON" NAME="Submit" VALUE="Block time" ONCLICK="BlockTime(this.form)"> </TD>
<TD align="center"> <INPUT TYPE="TEL" style="text-align: center" NAME="BlockTime" SIZE="35"></TD> </TR>
</TABLE>
</FORM>

<br />

<FORM NAME="TimeResult2">
<TABLE>
<TR> <TD align="center"> <INPUT TYPE="BUTTON" NAME="Submit" VALUE="Flight time" ONCLICK="BlockTime(this.form)"> </TD>
<TD align="center"> <INPUT TYPE="TEL" style="text-align: center" NAME="FlightTime" SIZE="35"></TD> </TR>
</TABLE>
</FORM>

</body>
</html>
 
Code:
--
d=new Date(2011,9,3,12,24);
[07:43:14.369] Mon Oct 03 2011 12:24:00 GMT-0600 (Mountain Daylight Time)
--
d2=new Date(2011,9,3,12,30);
[07:43:46.325] Mon Oct 03 2011 12:30:00 GMT-0600 (Mountain Daylight Time)
--
d2-d
[07:44:00.895] 360000
in milliseconds

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top