title: Javascript compare 2 dates and result must be setTimeout() Method in ms
body: <p>I'm trying to compare to 2 dates by hour/minutes/seconds, in order to make a script to resume a script when closed. If current <code>time</code> is pass <code>closed time + interval ( currently set at 30 minutes)</code> should execute and run the script normally, if not wait till <code>difference</code> timeouts to execute.</p>
  
  <p>Current hour/minutes/seconds is not a must but the result should be in ms interval</p>
  
  <p>Example:</p>
  
  <pre><code>interval = (30 * 60 * 1000)
  close time = 15:10:53
  current time = 15:15:29
  close time + interval = 15:40:53
  
  first time I check if `current time` &lt;= `close time + interval`
  then calculate `difference` 
  `difference` = (close time + interval = 15:40:53) - (current time = 15:15:29)
  
  Result should be setTimeout(function(){ alert("Hello"); }, time difference);
  </code></pre>
  
  <p>The only way I'm thinking of doing this is calculate each difference from Hour,Minutes,Seconds and then finding out the ms for setTimeout</p>
  
  <p>I tried but results were weird, not something that would count as smaller than 30min</p>
  
  <pre><code>var ONE_S = 1000 ;  
  var timeDiff = Math.abs(closeTime - currentTime); 
  var diffS = Math.round(timeDiff/ONE_S)
  </code></pre>