This can be achieved with very little Javascript.

Assuming that the “Created” time is dynamically displayed in a table with the format dd MMM yyyy hh:mm:ss , something like this should do the trick:
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> ElapsedTimeLogger = function(dateElementId, elapsedElementId, interval) { var container = $(elapsedElementId); var time = parseDate($(dateElementId).text()); var interval = interval; var timer; function parseDate(dateString) { var date = new Date(dateString); return date.getTime(); } function update() { var systemTime = new Date().getTime(); elapsedTime = systemTime - time; container.html(prettyPrintTime(Math.floor(elapsedTime / 1000))); } function prettyPrintTime(numSeconds) { var hours = Math.floor(numSeconds / 3600); var minutes = Math.floor((numSeconds - (hours * 3600)) / 60); var seconds = numSeconds - (hours * 3600) - (minutes * 60); if (hours < 10) hours = "0" + hours; if (minutes < 10) minutes = "0" + minutes; if (seconds < 10) seconds = "0" + seconds; var time = hours + ":" + minutes + ":" + seconds; return time; } this.start = function() { timer = setInterval(function() {update()}, interval * 1000); } this.stop = function() { clearTimeout(timer); } } $(document).ready(function () { var timeLogger = new ElapsedTimeLogger("#date", "#elapsed", 2); timeLogger.start(); $("#stop_timer").click(function() { timeLogger.stop(); }); $("#start_timer").click(function() { timeLogger.start(); }); }); </script> </head> <body> <table border="1"> <tr><th>Created</th><th>Timer</th></tr> <tr><td id="date">21 Feb 2013 12:30:00</td><td id="elapsed"></td></tr> </table> <input id="stop_timer" type="button" value="Stop timer"></input> <input id="start_timer" type="button" value="Start timer"></input> </body> </html>
Copy the above code into a file, say index.html and open it in a browser. I tested it on Chrome.
It should update the elapsed time every 2 seconds, but you can change the update interval to what suits you, for example. to update every 5 minutes:
new ElapsedTimeLogger("#date", "#elapsed", 300);
The general concept is to analyze the displayed "created" date in a timestamp (in milliseconds), and then calculate its difference with the current system time. To dynamically update the elapsed time, you use the Javascript setInterval function. To stop the elapsed time update, use the Javascript clearTimeout function.
I removed the prettyPrintTime function with powtac .
source share