views:

43

answers:

2

Hi folks,

on this website the textual time is dynamically updated .. i'm guessing using javascript.

this is the html code, using Firebug to inspect the page ...

<strong class="big" id="ct">Friday, 3 September 2010 at 8:17:21 AM</strong>

with that time value incremementing each second.

I'm guessing some javascript updates the 'ct' element .. but I can't find the code to how that's done?

Can anyone help?

+3  A: 

The javascript code on this page is obfuscated and that't probably why you can't find it. To achieve this you could use the setInterval function:

$(function() {
    setInterval(function() {
        $('#ct').html(new Date().toString());
    }, 1000);
});
Darin Dimitrov
@Darin Dimitrov - notice how you used `new Date()` ... what happens if i have my OWN date .. can that be used instead?
Pure.Krome
You could pass this date to the [constructor of the Date](http://www.w3schools.com/js/js_obj_date.asp) object.
Darin Dimitrov
A: 

You can also use setTimeout method as follows:

function updateTime() {
    var dtString = new Date().toString();
    $('#lblDate').html(dtString);
    setTimeout(updateTime,1000);
}
updateTime();

It's different than setInterval. setTimeout must be called again in each function call to make it work like setInterval.

Zafer