title: Getting difference in seconds from two dates in JavaScript
body: <p>I have dates stored in MongoDB using Date(), MongoDB uses UTC it's date type, and as a string looks like <code>Mon, 02 Apr 2012 20:16:31 GMT</code>.</p>
  
  <p>I want to get the difference in time, in total seconds, between this time and the current time (in UTC).</p>
  
  <p>I've tried this: </p>
  
  <pre><code>now = new Date();
  current_date = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
  end_date = obj.end_date (Mon, 02 Apr 2012 20:16:35 GMT);
  d = new Date(end_date - current_date);
  console.log(d.getSeconds());
  </code></pre>
  
  <p>This is displaying <code>22</code> for seconds, which obviously isn't right.</p>
  
  <p>It seems over complicated too.  Maybe there's a better way within MongoDB or a correct way within JavaScript to do this?</p>
  
  <p>Any suggestions would be great - thank you!</p>