title: Calculate time spent in javascript
body: <p>So I'm having a minor issue which is that I'm trying to inform the user how long they've been in a session.</p>
  
  <p>I have a heartbeat that stores the initial time when they enter the session, and also runs at an interval of 60 seconds and saves the new time in the DB. </p>
  
  <p>Now what I'd like to do is show time spent in minutes on the page on this id:</p>
  
  <pre><code>&lt;i id="minutes-in-session" class="text-muted"&gt;&lt;/i&gt;
  </code></pre>
  
  <p>my current heartbeat looks like this:</p>
  
  <pre><code>session.on('sessionConnected', function(event) {
    if (session.connection.data === 'customer') {
      $.post("/customers/" + customer_id + "/start", {
        started_at: Date(session.connection.creationTime)
      });
      setInterval((function() {
        return $.post("/customers/" + customer_id + "/heartbeat", {
          finished_at: Date.now()
        });
      }), 60000);
    }
  });
  </code></pre>
  
  <p>now I'm thinking I can add some javascript or jquery to update the timer in the class. But not sure how to calculate it. As you can see I also do a post request for the started_at</p>
  
  <p>So what I'd need to calculate is minutes between started_at and finished_at and update it when I set the new interval I believe.</p>