Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Position Clock

Status
Not open for further replies.

Montroze

Technical User
Apr 20, 2001
113
CA
Does anyone know how I can set this to show up elsewhere other then the top line of the page, want to put it in a border of a menu box...or have a script in this format,
 
Guess the script would help :)

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

<!-- Begin
var day=&quot;&quot;;
var month=&quot;&quot;;
var myweekday=&quot;&quot;;
var year=&quot;&quot;;
newdate = new Date();
mydate = new Date();
dston = new Date('April 4, 1999 2:59:59');
dstoff = new Date('october 31, 1999 2:59:59');
var myzone = newdate.getTimezoneOffset();
newtime=newdate.getTime();

var zone = 6; // references your time zone

if (newdate > dston && newdate < dstoff ) {
zonea = zone - 1 ;
dst = &quot; Central Savings Time&quot;;
}
else {
zonea = zone ; dst = &quot; Central Standard Time&quot;;
}
var newzone = (zonea*60*60*1000);
newtimea = newtime+(myzone*60*1000)-newzone;
mydate.setTime(newtimea);
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
myyear= mydate.getYear();
year = myyear;

if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // myhours = mydate.getHours();
if (myhours >= 12) {
myhours = (myhours == 12) ? 12 : myhours - 12; mm = &quot; PM&quot;;
}
else {
myhours = (myhours == 0) ? 12 : myhours; mm = &quot; AM&quot;;
}
myminutes = mydate.getMinutes();
if (myminutes < 10){
mytime = &quot;:0&quot; + myminutes;
}
else {
mytime = &quot;:&quot; + myminutes;
};
arday = new Array(&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;)
armonth = new Array(&quot;January &quot;,&quot;February &quot;,&quot;March &quot;,&quot;April &quot;,&quot;May &quot;,&quot;June &quot;,&quot;July &quot;,&quot;August &quot;,&quot;September &quot;, &quot;October &quot;,&quot;November &quot;,&quot;December &quot;)
ardate = new Array(&quot;0th&quot;,&quot;1st&quot;,&quot;2nd&quot;,&quot;3rd&quot;,&quot;4th&quot;,&quot;5th&quot;,&quot;6th&quot;,&quot;7th&quot;,&quot;8th&quot;,&quot;9th&quot;,&quot;10th&quot;,&quot;11th&quot;,&quot;12th&quot;,&quot;13th&quot;,&quot;14th&quot;,&quot;15th&quot;,&quot;16th&quot;,&quot;17th&quot;,&quot;18th&quot;,&quot;19th&quot;,&quot;20th&quot;,&quot;21st&quot;,&quot;22nd&quot;,&quot;23rd&quot;,&quot;24th&quot;,&quot;25th&quot;,&quot;26th&quot;,&quot;27th&quot;,&quot;28th&quot;,&quot;29th&quot;,&quot;30th&quot;,&quot;31st&quot;);
// rename locale as needed.

var time = (&quot;In Regina,Saskatchewan, it is: &quot; + myhours + mytime+ mm + &quot;, &quot; + arday[myday] +&quot;, &quot; + armonth[mymonth] +&quot; &quot;+ardate[myweekday] + &quot;, &quot; + year+&quot;, &quot; + dst +&quot;.&quot;);
document.write(time);
//-->
</SCRIPT>
 
Hi Montroze,

I kept your time script the same excepting for the last line of code.Besides I inserted your script into a function named 'showtime()'.Of course you may name it what you want.
Instead of using 'document.write(time)', I replaced it for
the 'innerText' property.
As you can see the last line of code looks as follows:

timelocation.innerText = time;

Then I gave an id=&quot;timelocation&quot; to the cell where time is displayed.By giving an id to the cell you can access it easily for scripting.In this case for displaying the time into the cell.So,using innerText property you can put the value of the variable 'time' in the cell.
Of course you can layout your page the way you like.
This is just an example.

Here is the complete code:


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>DISPLAYING TIME</title>
<script language=&quot;JavaScript&quot;>
<!-- Begin
function showtime()
{
var day=&quot;&quot;;
var month=&quot;&quot;;
var myweekday=&quot;&quot;;
var year=&quot;&quot;;
newdate = new Date();
mydate = new Date();
dston = new Date('April 4, 1999 2:59:59');
dstoff = new Date('october 31, 1999 2:59:59');
var myzone = newdate.getTimezoneOffset();
newtime=newdate.getTime();
var zone = 6; // references your time zone
if (newdate > dston && newdate < dstoff ) {
zonea = zone - 1 ;
dst = &quot; Central Savings Time&quot;;
}
else {
zonea = zone ; dst = &quot; Central Standard Time&quot;;
}
var newzone = (zonea*60*60*1000);
newtimea = newtime+(myzone*60*1000)-newzone;
mydate.setTime(newtimea);
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
myyear= mydate.getYear();
year = myyear;

if (year < 2000) // Y2K Fix, Isaac Powell
{year = year + 1900;} // myhours = mydate.getHours();
if (myhours >= 12) {
myhours = (myhours == 12) ? 12 : myhours - 12; mm = &quot; PM&quot;;
}
else {
myhours = (myhours == 0) ? 12 : myhours; mm = &quot; AM&quot;;
}
myminutes = mydate.getMinutes();
if (myminutes < 10){
mytime = &quot;:0&quot; + myminutes;
}
else {
mytime = &quot;:&quot; + myminutes;
};
arday = new Array(&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;)
armonth = new Array(&quot;January &quot;,&quot;February &quot;,&quot;March &quot;,&quot;April &quot;,&quot;May &quot;,&quot;June &quot;,&quot;July &quot;,&quot;August &quot;,&quot;September &quot;, &quot;October &quot;,&quot;November &quot;,&quot;December &quot;);
ardate = new Array(&quot;0th&quot;,&quot;1st&quot;,&quot;2nd&quot;,&quot;3rd&quot;,&quot;4th&quot;,&quot;5th&quot;,&quot;6th&quot;,&quot;7th&quot;,&quot;8th&quot;,&quot;9th&quot;,&quot;10th&quot;,&quot;11th&quot;,&quot;12th&quot;,&quot;13th&quot;,&quot;14th&quot;,&quot;15th&quot;,&quot;16th&quot;,&quot;17th&quot;,&quot;18th&quot;,&quot;19th&quot;,&quot;20th&quot;,&quot;21st&quot;,&quot;22nd&quot;,&quot;23rd&quot;,&quot;24th&quot;,&quot;25th&quot;,&quot;26th&quot;,&quot;27th&quot;,&quot;28th&quot;,&quot;29th&quot;,&quot;30th&quot;,&quot;31st&quot;);
// rename locale as needed.

var time = &quot;In Regina,Saskatchewan, it is: &quot; + myhours + mytime+ mm + &quot;, &quot; + arday[myday] +&quot;, &quot; + armonth[mymonth] +&quot; &quot;+ardate[myweekday] + &quot;, &quot; + year+&quot;, &quot; + dst +&quot;.&quot;;
timelocation.innerText = time;
}
//-->
</script>
<style type=&quot;text/css&quot;>
.class1
{
font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size : 10pt;
font-weight : bolder;
color : Black;
}
</style>
</head>
<body onload=&quot;showtime()&quot;>
<br><br><br><br>
<table width=&quot;100%&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; align=&quot;center&quot; bordercolor=&quot;#000000&quot;>
<tr>
<td align=&quot;center&quot;>
<p class=&quot;class1&quot;>This example shows how to display the time where you wish</p>
</td>
</tr>
<tr>
<td align=&quot;center&quot;>
</td>
</tr>
<tr>
<td align=&quot;center&quot;>
<p class=&quot;class1&quot; id=&quot;timelocation&quot;> </p>
</td>
</tr>
</table>
</body>
</html>



I hope this helps,


Kind Regards :)

alexfusion
 
Thanks a lot for the fix-up...much appreciated!
 
One problem is that the proposed script won't work in Netscape browsers because object.innerText is not supported. A way to get it to work in both browsers is to have the function return the string 'time' to the function call, which is embedded in the HTML in the spot where you want the time to appear.

try these simple fixes:
Code:
//timelocation.innerText = time;(REMOVE THIS LINE)
return time//(ADD THIS LINE)
Change the HTML to this:
Code:
<p class=&quot;class1&quot; id=&quot;timelocation&quot;>
<script language=&quot;javascript&quot;>
document.write(showtime())
</script>
</p>


This works in at least both major browsers (including NS 4.x and NS 6.x).

I hope this helps!
 
Hi guys,
Thank you, Montroze for your response.It feels good when someone tells that the answer is useful.
LScott,you are totally correct.Netscape doesn't support object.innerText.
I forgot this issue.I'm sorry.
The modifications you pointed are very good.Thank you for your observation.It is useful to me.

Kindest Regards

alexfusion
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top