I have a HTML table which has records pulled in from the database. I\'m using PHP/MySQL.
The Column in my table named \"Timer\" is not retrieved from the database. I nee
This can be achieved with very little Javascript.
Assuming that the "Created" time is rendered dynamically in the table with format dd MMM yyyy hh:mm:ss
, something like this should do the trick:
Created Timer
21 Feb 2013 12:30:00
Copy the code above 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 may change the update interval to something that suits you, e.g. to make it update every 5 minutes:
new ElapsedTimeLogger("#date", "#elapsed", 300);
The general concept is to parse the rendered "Created" date into an epoch timestamp (in milliseconds) and then compute its difference with the current system time. To get the elapsed time updating dynamically you use Javascript's setInterval
function. To stop updating the elapsed time use Javascript's clearTimeout
function.
I lifted the prettyPrintTime
function from powtac.