title: How do I convert milliseconds to a TDateTime?
body: <p>I'm doing a long loop downloading thousands of files. I would like to display an estimated time remaining, since it could take hours. However, with what I've written, I get an average number of <em>milliseconds</em>. How do I convert this average download time from milliseconds to a <code>TDateTime</code>?</p>
  
  <p>See where I'm setting <code>Label1.Caption</code>:</p>
  
  <pre><code>procedure DoWork;
  const
    AVG_BASE = 20; //recent files to record for average, could be tweaked
  var
    Avg: TStringList; //for calculating average
    X, Y: Integer; //loop iterators
    TS, TE: DWORD; //tick counts
    A: Integer; //for calculating average
  begin
    Avg:= TStringList.Create;
    try
      for X:= 0 to FilesToDownload.Count - 1 do begin //iterate through downloads
        if FStopDownload then Break; //for cancelling
        if Avg.Count &gt;= AVG_BASE then //if list count is 20
          Avg.Delete(0); //remove the oldest average
        TS:= GetTickCount; //get time started
        try
          DownloadTheFile(X); //actual file download process
        finally
          TE:= GetTickCount - TS; //get time elapsed
        end;
        Avg.Add(IntToStr(TE)); //add download time to average list
        A:= 0; //reset average to 0
        for Y:= 0 to Avg.Count - 1 do //iterate through average list
          A:= A + StrToIntDef(Avg[Y], 0); //add to total download time
        A:= A div Avg.Count; //divide count to get average download time
        Label1.Caption:= IntToStr(A); //&lt;-- How to convert to TDateTime?
      end;
    finally
      Avg.Free;
    end;
  end;
  </code></pre>
  
  <p>PS - I'm open to different ways of calculating the average speed of the last 20 (or AVG_BASE) downloads, because I'm sure my string list solution isn't the best. I don't want to calculate it based on all downloads, because speed may change over that time. Therefore, I'm just checking the last 20.</p>