Customizing SMF > Tips and Tricks

Live clock in header

(1/33) > >>

Joker™:
I was trying to make this from a long long time , and with the help of a friend and a book at last achieved it.

Live clock is a dynamic clock and not a static clock as we have in header of default SMF 2.0 RC3. I was trying to make the clock in such a way that it should be using as minimum resources as possible .
As it's not my alone work so not making a package of it (might someone may move it to appropriate board if it is in wrong place).

So to make it just make these following edits (make backup of the file before editing it).

open themes\default\index.template.php
Find:

--- Code: --- echo '
<li>', $context['current_time'], '</li>
</ul>';
--- End code ---

Replace it with:

--- Code: --- echo '

<li>',timeformat(time(),'%B, %d, %Y'), '
<li id="clock">Loading...</li>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function refrClock()
{
var d=new Date();
var s=d.getSeconds();
var m=d.getMinutes();
var h=d.getHours();
var am_pm;
if (s<10) {s="0" + s}
if (m<10) {m="0" + m}
if (h>12) {h-=12;am_pm = "pm"}
else {am_pm="am"}
if (h<10) {h="0" + h}
document.getElementById("clock").innerHTML=h + ":" + m + ":" + s + am_pm;
setTimeout("refrClock()",1000);
}
refrClock();
// ]]></script>
</li></ul>';
--- End code ---

Hope you guys will like this small piece of code :).

For live demo can visit freakygurus.com (You need to login to see the clock)

Edit: Now the clock code is compatible with "W3C Markup Validation"

xenovanis:
Hi Joker™  :)

Thanks for sharing. I visited your site but I can't find the clock.  ??? Is it me?

Joker™:
you need to login to see it . this is the screen shot

K@:
If you want a clock that can handle different timezones, such as the one I have here, just below the banner:

http://www.tlakoc.org.uk

Gimme a shout.

Joker™:

--- Quote from: K@ on September 02, 2010, 12:44:37 PM ---If you want a clock that can handle different timezones, such as the one I have here, just below the banner:

http://www.tlakoc.org.uk

Gimme a shout.

--- End quote ---
surely like to see the code .

But i think the clock code we made gets the user time zone itself , one doesn't have to make time zone settings (i've not tested it completely , someone can give me a feedback).

Navigation

[0] Message Index

[#] Next page

Go to full version