title: JavaScript Date to Delphi TDateTime
body: <p>I need to send via AJAX a date for a delphi server that accept the date in float format and set a <code>TDateTime</code> property.</p>
  
  <p>Eg.</p>
  
  <pre><code>var
     date: TDateTime;
  begin
     date := StrToFloat(Request.QueryFields.Values['date']);
  end;
  </code></pre>
  
  <p>Delphi TDateTime start from 30/12/1989, i have tested with:</p>
  
  <pre><code>var
     date: TDateTime;
  begin
     date := StrToFloat('0');
     ShowMessage( DateTimeToStr(date) ); // show: 30/12/1899
  end;
  </code></pre>
  
  <p>JavaScript Date start from unix epoch, i have tested with:</p>
  
  <pre><code>console.log(new Date(0)); // Thu Jan 01 1970 01:00:00 GMT+0100
  </code></pre>
  
  <p>a simple conversion seem subtract the difference, but doesn't works, eg.:</p>
  
  <pre><code>// javascipt
  var delphiTime = (new Date("07-24-2019") - new Date("12-30-1899")) / 1000;
  console.log(delphiTime ); // 3773084400
  
  
  // delphi
  ShowMessage( DateTimeToStr(3773084400) ); // show 00/00/00
  </code></pre>
  
  <p>the strange fact, on delphi, <code>Now</code> is 43670.654378:</p>
  
  <pre><code>ShowMessage( FloatToStr(Now) ); // 43670.654378
  </code></pre>
  
  <p>In delphi 0 is 1899 and 43670 is 2019...</p>
  
  <p>How works the date format in Delphi and how convert a unix date to delphi date with math?</p>
  
  <p>Side note: i can't modify the server, i need to solve the issue client side with javascript</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>In Delphi the float value = 1 would be 31.12.1899, 2 = 01.01.1900 and so on. Each unit seem a day.</p>
  
  <pre><code>function jsDateToDelphiDate(date){
    const seconds = (new Date(date).getTime() - new Date("12-30-1899").getTime()) / 1000;
    const days = seconds / 60 / 60 / 24;
    return days;
  }
  
  console.log(jsDateToDelphiDate(new Date("07-24-2019 16:00:00"))); // 43670.625
  </code></pre>
  
  <p><code>43670.625</code> on delphi is <code>23/07/2019 15:00</code>.</p>
  
  <p><strong>Why i lose 1 hour?</strong></p>