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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adjust time and date?

Status
Not open for further replies.

Beat

Technical User
Aug 26, 2001
41
0
0
SE
I am displaying date and time on a website, by <%Now%> formatted with tags from Dreamweaver. (You can choose format to be applied to records from a recordset, and I have copied the tags from there.)

the website is now hosted on a NZ server, but it is a Swedish website.

What I really want to do is to use a script that displays the accurate time and date where the visitor is viewing the website from. Showing local time.

Or, otherwise I just want to know how to adjust the script I am using now to display the accurate time in Sweden.

Thanks!
 
buddy of mine - mlawson gave me this. And to be truthful, I no longer remember where he had gotten it from.

paste this code where you want the time to show on your webpage


<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
var __clock_astrMonths = new Array(&quot;Jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;May&quot;,&quot;Jun&quot;,&quot;Jul&quot;,&quot;Aug&quot;,&quot;Sep&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;);
var __clock_astrDays = new Array(&quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, &quot;Wed&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;);

function clock_getTime(i_bHideSeconds) {
var Digital=new Date();
var hours=Digital.getHours();
var minutes=Digital.getMinutes();
var seconds=Digital.getSeconds();
var dn=&quot; AM&quot;;
if (hours>12){
dn=&quot; PM&quot;;
hours=hours-12;
}
if (hours==0) hours=12;
if (minutes<=9) minutes=&quot;0&quot;+minutes;
if (seconds<=9) seconds=&quot;0&quot;+seconds;
var strDate = __clock_astrDays[Digital.getDay()] + &quot; &quot; + Digital.getDate() + &quot; &quot; + __clock_astrMonths[Digital.getMonth()] + &quot; &quot; + Digital.getFullYear();
return strDate + &quot; &quot; + hours + &quot;:&quot; + minutes + ((i_bHideSeconds) ? &quot;&quot; : &quot;:&quot; + seconds) + dn;
}

function clock_showClock(){
var tme = clock_getTime();
if (document.getElementById)
{ //write updated date/time (including seconds) to DHTML browser
document.getElementById(&quot;divClock&quot;).innerHTML = '<FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=1 color=&quot;#000000&quot;>' + tme + '</font>';
} else {
if(document.all) {
// If IE4.0
document.all(&quot;divClock&quot;).innerHTML = '<FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=1 color=&quot;#000000&quot;>' + tme + '</font>';
} else {
// If Netscape
document[&quot;divClock&quot;].document.open();
document[&quot;divClock&quot;].document.write(&quot;<table border='0' width='150' height='20' cellpadding='0' cellspacing='0'><tr>&quot;);
if(document.bgColor.toLowerCase()==&quot;#ffffff&quot;) {
document[&quot;divClock&quot;].document.write(&quot;<td valign='top' align='right'><font face='arial' color='#000000' style='font-size:9pt'>&quot; + tme + &quot;</font></TD></TR></table>&quot;);
} else {
document[&quot;divClock&quot;].document.write(&quot;<td valign='top' align='right'><font face='arial' color='#000000' style='font-size:9pt'>&quot; + tme + &quot;</font></TD></TR></table>&quot;);
}
document[&quot;divClock&quot;].document.close();
}
}
}
if (document.getElementById || document.all) {
document.write ('<DIV NAME=&quot;divClock&quot; ID=&quot;divClock&quot;><FONT face=&quot;Arial, Helvetica, sans-serif&quot; size=1 color=&quot;#000000&quot;>' + clock_getTime() + '</font></DIV>');
//Update Clock each second...
setInterval(&quot;clock_showClock()&quot;,1000);
} else {
document.write(&quot;<LAYER bgcolor='&quot; + document.bgColor + &quot;' id='divClock' name='divClock' left='600' top='187' width='155' height='20'>&nbsp;</LAYER>&quot;);
setInterval(&quot;clock_showClock()&quot;,1000);
//document.write (clock_getTime(true));
}


//-->
</SCRIPT>
&quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Damned nice little bit of code there Stuart. Very Clean looking.

Cheech The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Thanks - but it isnt mine - wish it was.

And really wish I could recall the author to give proper credit where credit is due.

Whoever it was - did indeed do a nice job. &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
thanks!!!

and apperantly is a good one too, according to the other responses here..

there is only one problem...... I copy this code and paste it on to a page to test it, but nothing is displayed...... The page comes up empty.....

What am I doing wrong?? Do I have to modify the code or something to make it happen, or???

Please help!!!

Appreciate your ealrier response.
 
it should show right up

its using layers too though.

Did you upload it to the web? &quot;Never underestimate the power of determination&quot;

Stuart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top