Author |
Message |
wiz
Involved


Joined: Oct 09, 2006
Posts: 413
Location: UK
|
Posted:
Sat Feb 21, 2009 11:13 am |
|
Hi, im trying to mod the Fisubice header. In line 151 of theme.php the variable $datetime is assigned to the javascript to calculate the date.
Currently, i have changed it to this:
Code:$datetime = gmdate("D jS M G:i T ");
|
But ideally i would like the time to be 'live' and current, so after a while digging around various sites i found this code:
Code:<script type="text/javascript">
function live_clock()
{
var today = new Date();
var second = today.getSeconds();
var minute = today.getMinutes();
var hour = today.getHours();
var hour24 = today.getHours();
var ampm = "";
var day = today.getDay();
var date = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
var days = new Array();
days[0] = "Sun";
days[1] = "Mon";
days[2] = "Tues";
days[3] = "Wed";
days[4] = "Thurs";
days[5] = "Fri";
days[6] = "Sat";
var mns = new Array();
mns[0] = "Jan";
mns[1] = "Feb";
mns[2] = "Mar";
mns[3] = "Apr";
mns[4] = "May";
mns[5] = "June";
mns[6] = "July";
mns[7] = "Aug";
mns[8] = "Sept";
mns[9] = "Oct";
mns[10] = "Nov";
mns[11] = "Dec";
if(second<10)
{
second = "0"+second;
}
if(minute<10)
{
minute = "0"+minute;
}
if(hour24<=12)
{
ampm = "AM";
}
else
{
ampm = "PM"
}
if(hour24>=12)
{
hour= hour-12;
}
if(hour24==0)
{
hour=12;
}
document.getElementById('live_clock').innerHTML=(hour+":"+minute+":"+second+" "+ampm+', '+date+' '+mns[month]+' '+year);
}
</script>
<body onLoad="setInterval('live_clock()', 1000);"><div id="live_clock"></body>
|
But no matter how i try it, i cannot get it to work; can anyone help me.
Cheers
WIZ |
|
|
|
 |
spasticdonkey
RavenNuke(tm) Development Team

Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Sat Feb 21, 2009 1:37 pm |
|
my guess would be the body onload statement, but I'm not JS expert. Is there another way to initiate the script? |
|
|
|
 |
wiz

|
Posted:
Sat Feb 21, 2009 1:43 pm |
|
i dont know because im not a JS expert either, the gmdate function looks great for displaying GMT time, but i just would like to to update |
|
|
|
 |
spasticdonkey

|
Posted:
Sat Feb 21, 2009 1:58 pm |
|
your page should only have one body tag, so that code above would only have the live clock as content, since the body tag is closed afterward... just wanted to make sure you were adding that to your one-and-only body tag.
This is a similar clock that also uses body onload, but references the js as an external file, might try that....
http://www.dynamicdrive.com/dynamicindex6/clock2.htm |
|
|
|
 |
wiz

|
Posted:
Sat Feb 21, 2009 2:02 pm |
|
Nice one..ill have a play with that after dinner
Cheers
WIZ |
|
|
|
 |
wiz

|
Posted:
Sat Feb 21, 2009 4:58 pm |
|
I used the script that spasticdonkey listed..nice little bit of javascript there. However i followed the rule of double quoting for php etc, and all it does is echo the onload command..so again, spasticdonkey you are right, it is the onload.
Here is the current code that i have...
Code:// Live Date and Time
datetime = "<script type='text/javascript' src='liveclock.js'></script>"."\n\n"
onLoad="show_clock()";
// End Live Date and Time
|
Cheers
WIZ |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 1:38 am |
|
I would undo the changes you did to the date and time, in case it is used elsewhere in your theme. The JS will display the time and it will read from the clients' computer so it doesn't need to be aware of the site time.
In your theme find the opening <body> tag and change to:
<body onLoad="show_clock()">
then wherever the theme displays the $datetime variable replace with the call to the external js script. Not familiar with your theme, but in fisubice it would be (themes/fisubice/header.html)
Code:<font class="content">
$datetime
</font>
|
change to
Code:<font class="content">
<script type="text/javascript" src="liveclock.js">
/*
Live Clock Script-
By Mark Plachetta (astro@bigpond.net.au©) based on code from DynamicDrive.com
For full source code, 100's more DHTML scripts, and Terms Of Use,
visit http://www.dynamicdrive.com
*/
</script>
</font>
|
keep in mind that particular layout is in html, and yours may be in php, also assumes that the liveclock.js is in the root directory |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 8:37 am |
|
My theme is Fisubice. I got sick and tired of old scripts and 'half made' themes; so i wrote this one from fisubice, change a few colours, images and classes, thats all
Ive changed the $datetime var in header.html as you suggested. However i cannot find a body tag anywhere. Infact the only body i can see is a CSS class.
Am i missing something vital here? |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 11:23 am |
|
line 143 in fisubice/theme.php, find:
echo '<body bgcolor="#FFFFFF" text="#516A88" style="margin: 10px">';
change to:
echo '<body onLoad="show_clock()" bgcolor="#FFFFFF" text="#516A88" style="margin: 10px">'; |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 11:51 am |
|
i can confirm that i have changed header.html and theme php as you suggest..but no cigar. liveclock.js is in my theme root folder. |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 11:56 am |
|
i see body onload twice in your page source |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 12:12 pm |
|
yep i can view this (in seamonkey). I have changed the path in header.html as you suggested..still no cigar  |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 12:36 pm |
|
hmm i got it working in fisubice, so something may be amiss. If you want to zip up your theme.php and header.html and pm me a link i'll have a look |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 12:48 pm |
|
Thanks a lot for taking the time, i hope this is usefull and not a waste of peoples time.
PM sent
cheers
WIZ |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 1:17 pm |
|
Excellent work SpasticDonkey it now displays..thankyou. I just have to change the format now..so technically...Problem Solved  |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 1:18 pm |
|
sweet
there are options for the text color in the js file  |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 1:22 pm |
|
yes...but for some reason i have date only displayed.. |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 2:36 pm |
|
the date is still pulled from theme.php, so if the time disappeared then there might be a syntax error in the js file when you edited the style. if it works only on some pages, then you might have a js conflict with another js file, which happens at times when using body onload
i see it now displayed as: 2/22/2009 test14:36:44 |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 2:41 pm |
|
now i dont see that...in AOL, IE7 and seamonkey, i only see the date and i have used ctrl+F5, i did add the text "test" to see my changes..but i see none of it |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 6:15 pm |
|
It's showing for me in IE and Firefox
I shortened the date since that TD is only 165px wide, you might not have room to write much in between the date and time, or there could be layout issues in some browsers |
|
|
|
 |
wiz

|
Posted:
Sun Feb 22, 2009 6:37 pm |
|
all i see is the date, but if you see something..then why shouldnt I? |
|
|
|
 |
spasticdonkey

|
Posted:
Sun Feb 22, 2009 7:09 pm |
|
not sure i have a good answer there... i'd say clear you browser cache but if it appears that way in multiple browsers, i dunno..... you could try..  |
|
|
|
 |
pan
Involved


Joined: Jul 25, 2006
Posts: 354
|
Posted:
Wed Mar 11, 2009 9:31 pm |
|
i have read this thread over and over and cannot understand it.
i just want a clock on my site set to GMT +10  |
|
|
|
 |
wiz

|
Posted:
Wed Mar 11, 2009 10:00 pm |
|
well that depends on if you want a static clock...e.g a fixed time, that only changes when the user changes or refreshes the page. If you want one that counts, you must use javascript, like i did.
The static one is easy.
Look in your themes header.tpl to see if it has the $datetime variable. If not create it wherever you want it displayed.
Then go to your theme.php and find (or create) the $datetime variable
and make sure it now reads...
$datetime = date("D jS M G:i T ");
Before this line..add this line
date_default_timezone_set('UTC'); //where UTC is your timezone.This will adjust the server time to your desired time//
you can adjust the output by changing the time constants, you can find it all here..
http://us2.php.net/manual/en/function.date.php |
|
|
|
 |
|