title: How to compare a C# DateTime to Javascript's Date.now()
body: <p>I have some javascript that only needs to execute if it's been less than so-many-seconds since a date that is calculated on the server, but I'm having some trouble with the date comparison. Here's what I've tried:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var elapsedMillis = 10000;
      if(Date.now() - &lt;%=(benchmarkDate-new DateTime(1970,1,1)).TotalMilliseconds%&gt; &lt; elapsedMillis)
      {
          //do stuff
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Unfortunately, the C# TimeSpan is giving me a number of milliseconds that varies from JavaScript's Date.now() by about 14,000 seconds even if executed within ten seconds of setting benchmarkDate.</p>