



Esta função monta um cronometro com o tempo decorrido.
Ótimo para descobrir os segundos de diferença.
Código fonte:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | function TimeBetween(aDateStart, aDateEnd: TDateTime): String; var Hour, Minute, Second: Integer; begin Result := ''; if (aDateStart < aDateEnd) then Second := Round(86400 * (aDateEnd - aDateStart)) else Second := Round(86400 * (aDateStart - aDateEnd)); Hour := Second div 3600; Second := Second - (Hour * 3600); Minute := Second div 60; Second := Second - (Minute * 60); if (Hour > 0) then begin if (Length(IntToStr(Hour)) > 2) then Result := IntToStr(Hour) else Result := FormatFloat('00', Hour); end else Result := FormatFloat('00', 0); Result := Result + ':' + FormatFloat('00', Minute) + ':' + FormatFloat('00', Second); end; |
Exemplo de uso:
1 2 3 4 | procedure TForm1.Timer1Timer(Sender: TObject); begin LblTime.Caption := TFunctions.TimeBetween(Inicio, Now); end; |