TimeSpanAddSubtract (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

These lines of code will exemplify the Parse, Add, and Subtract functions included in the TimeSpan unit.

Code

begin
  { Parse two different time spans as strings. }
  TS1 := TTimeSpan.Parse('25.10:32:25.25');
  TS2 := TTimeSpan.Parse('20.23:36:27.63');

  { Try to subtract TS2 from TS1, if possible. }
  if (TS1 > TS2) then { Operator ">" is overloaded. }
  begin
    TS3 := TS1.Subtract(TS2);
    Writeln('Subtracting TS2 from TS1 is: ' + String(TS3));
  end;

  { Add TS1 to TS3. }
  TS4 := TS1.Add(TS3);
  Writeln('Adding TS1 to TS3 is: ' + String(TS4));
  Readln;
end.

Uses