<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'Get the time elapsed between two intervals'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Wed, 19 Jun 2013 09:27:18 GMT</pubDate>
<item>
<title>meetar said on 5/16/11</title>
<link>http://snipplr.com/view/3773/get-the-time-elapsed-between-two-intervals/</link>
<description><![CDATA[ This is incorrect!

getMilliseconds() returns the number of milliseconds into the current second of the timestamp contained by the Date(), like a modulo (%) for milliseconds. If used with an unset Date() object, it will return the number of milliseconds into the current second of the current clock time. So this code will only return a number from 0-999.

You can check this with this code:

var foo = new Date();
setTimeout( function() {
  var bar = new Date();
  var baz = new Date();
  baz.setTime(bar.getTime() - foo.getTime());
  alert(baz.getMilliseconds() + " ms elapsed between the definition of foo and bar.");
}, 2500);

The result will be close to 500, instead of 2500.

Here's a better way to do it:

var foo = new Date();
var bar = new Date();
var diff = bar - foo;
alert(diff + " ms elapsed between the definition of foo and bar."); ]]></description>
<pubDate>Mon, 16 May 2011 04:36:46 GMT</pubDate>
<guid>http://snipplr.com/view/3773/get-the-time-elapsed-between-two-intervals/</guid>
</item>
</channel>
</rss>