Customizing SMF > Tips and Tricks

Live clock in header

<< < (25/33) > >>

ChalkCat:
Please help, how do I:

a) display the day of the week? (3 letter format preferred)
b) change the month to three letter format?
c) display st or th after the date number? (low priority)

Currently my clock displays as

I wanted 24 hour format with the date in British order and didn't want to display the seconds, so I have played around and my code currently looks like this:



--- Code: ---timeformat(time(),'%d %B %Y'), '
<font id="clock">Loading...</font>
<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<10) {h="0" + h}
document.getElementById("clock").innerHTML=h + ":" + m;
setTimeout("refrClock()",1000);
}
refrClock();
// ]]></script> </li>
</ul>';
--- End code ---

I have tried adding the variable %D for the day, but that just gives the whole date again as "03/21/12", and %M which should be the three letter month just gives the arbitrary number 8, so I can't figure out which formatting system this is using.

Thanks.

ChalkCat:
Bumpity-bump.  I'm sorry but this is really bugging me, we would rather have a static clock that shows the correct day rather than a live one that doesn't.  Please can anyone tell me what to do just to get the weekday showing, Thu, Fri, etc.?  It must be possible, but feeding in all the D and other letters I can find just isn't helping.

riou:
The code would be (of course you can change how it displays and such :p) :


--- Code: ---<font id="clock">Loading...</font>
<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 day=new Array();
day[0]="Sun";
day[1]="Mon";
day[2]="Tue";
day[3]="Wed";
day[4]="Thu";
day[5]="Fri";
day[6]="Sat";
var a = day[d.getDay()];
var month=new Array();
month[0]="Jan";
month[1]="Feb";
month[2]="Mar";
month[3]="Apr";
month[4]="May";
month[5]="Jun";
month[6]="Jul";
month[7]="Aug";
month[8]="Sep";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";
var b = month[d.getMonth()];
var c=d.getFullYear();
var e=d.getDate();
var am_pm;
if (s<10) {s="0" + s}
if (m<10) {m="0" + m}
if (h<10) {h="0" + h}
document.getElementById("clock").innerHTML=h + ":" + m + ":" + s + " " + a + " " + b + " " + e + " " + c;
setTimeout("refrClock()",1000);
}
refrClock();
// ]]></script>
--- End code ---

ChalkCat:
Wonderful thank you  :D

I just woke up on the sofa so I shall have a play with this tomorrow - thank you :)

Old Fossil:

--- Quote from: Sabrinova on March 24, 2012, 09:42:14 PM ---Wonderful thank you  :D

I just woke up on the sofa so I shall have a play with this tomorrow - thank you :)

--- End quote ---

Whatever were ya doing on the sofa?

 :-[

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version