Sunday, January 9, 2011

calculating difference of time in Delphi

: How can I calculate a difference of time?
: I have a program that begin at 12:00:10,200 and
: finish at 12:10:00,560 for example.
: I need to calculte the difference between two.

Declare two Delphi TDateTime variables, e.g. T1 for the starting time and T2 for the ending time.
To measure and display the time span that a process takes:

T1 := Now;
Label1.Caption := FormatDateTime('"Start: " hh:nn:ss.zzz', T1);
// Process that you want to time:...
// ...
T2 := Now;
Label2.Caption := FormatDateTime('"Stop: " hh:nn:ss.zzz', T2);
Label3.Caption := FormatDateTime('"Diff: " hh:nn:ss.zzz', T2 - T1);
 
 
 
Try another code below
Get the time difference between one event and another one :
 
Initialize start and elapsed time variables that are visible to both events:


var
StartTime: TDateTime;
ElapsedTime: TDateTime;

procedure YourForm.Event1(Sender: TObject);
begin
StartTime := Now;
end;

procedure YourForm.Event2(Sender: TObject);
begin
ElapsedTime := Now - StartTime;
Label1.Caption := FormatDateTime('hh:mm:ss.ss', ElapsedTIme);
end;
 
 
 
 
 

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum