Quite often, the UTC timestamps returned through JSON queries are in an ISO 8601 format (e.g. as returned by the JSON interface to the MediaWiki software that powers Wikipedia). Before performing date arithmetic, you will need to convert that to a format that the web browser will recognize.
(See http://stackoverflow.com/questions/3566125/problem-with-date-formats-in-javascript-with-different-browsers/3567007#3567007 for how to do this using regular expressions.)
Then you will need to subtract that time (new Date(timeString.replace(...)...)
) from the current time (new Date()
). That will give you the interval between the two times in milliseconds (1 second = 1000 milliseconds).
Be aware that this is affected by the accuracy of the client computer's system clock, which you have no control over if you are operating a public web site. If this is the case, you should compare times on your server or at least allow your server to send the accurate time to the client over JSON.