this slowpoke moves

Round System Time

function RoundTime(ADate: string; Rounding: Integer; bRound: Boolean): string;
var
  Year, Month, Day, Hour, Min, Sec, MSec: Word;
  tmpDate: TDateTime;
  Res, Diff: string;
  M: integer;
begin
  tmpDate := StrToDateTime(ADate);
  DecodeTime(tmpDate, Hour, Min, Sec, MSec);
  if (Rounding > 0) and (bRound = True) then
  begin
    if Min mod Rounding = 0 then
      Res := IntToStr(Min)
    else
      Res := IntToStr(Round(Min / Rounding) * Rounding);
    M := StrToInt(Copy(ADate, Length(ADate) - 1, 2));
    Diff := IntToStr(StrToInt(Res) - M);
    if Copy(Diff, 1, 1) = '-' then
    begin
      Diff   := Copy(Diff, 2, Length(Diff) - 1);
      Result := FormatDateTime('dd.mm.yy hh:mm', (tmpDate - StrToTime('00:00' + Diff)));
    end
    else
      Result := FormatDateTime('dd.mm.yy hh:mm', (tmpDate + StrToTime('00:00' + Diff)));
  end
  else
    Result := ADate;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := FormatDateTime('dd.mm.yy hh:mm', Now);
  Edit2.Text := RoundTime(Edit1.Text, SpinEdit1.Value, Checkbox1.Checked);
end;


Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate