I have a div like so:
<div id="time_text"></div>
I want to be able to retrieve the current time automatically every seconds (or few seconds) then update the innertext of that div with the current time retrieved. I found this function online that updates the time:
function getTime(offset){
var now = new Date();
var hour = 60*60*1000;
var min = 60*1000;
return new Date(now.getTime() + (now.getTimezoneOffset() * min) + (offset * hour));
}
How would I use that function to get the time automatically, then update the innerText of my div?
Thanks.
use setInterval to update your time
This will update the time in every 5 seconds
Here is the working sample : http://jsfiddle.net/8Av5d/11/