Hiya:) How do you display the current date/time on a web site?

admin

Administrator
Staff member
Hiya:) How do you display the current date/time on a web site? I have checked out a few other resources but I didnt really understand what was going on .. heh .. I would really appreciate the help since I am such an html n00b :)<br />
<br />
Thx:)<!--content-->heh ok :)<br />
<br />
I know im replying to myself BUT I was wondering if anyone knew how to get users info in order to dispay the correct current date from their location on my site:)<br />
<br />
A URL or something would really be helpful, in the meantime I will keep looking.<br />
<br />
Thx:)<!--content-->Hi!<br />
<br />
Hope this will work for you, of not go to:<br />
<!-- m --><a class="postlink" href="http://www.dynamicdrive.com/dynamicindex6/index.html">http://www.dynamicdrive.com/dynamicindex6/index.html</a><!-- m --><br />
<br />
<br />
Step 1: Add the below code where you wish the clock to appear on the page:<br />
<br />
<script language="javascript" src=http://www.htmlforums.com/archive/index.php/"liveclock.js"><br />
<br />
/*<br />
Live Clock Script-<br />
By Mark Plachetta (<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->? based on code from DynamicDrive.com<br />
For full source code, 100's more DHTML scripts, and Terms Of Use,<br />
visit <!-- m --><a class="postlink" href="http://www.dynamicdrive.com">http://www.dynamicdrive.com</a><!-- m --><br />
*/<br />
<br />
</script><br />
<br />
Step 2: Inside the <BODY> tag itself, throw in the following onLoad event handler, as follows:<br />
<br />
<body onLoad="show_clock()"><br />
Step 3: Finally, you have a big decision to make. This script requires one of the below two .js files to operate...which one to Download <!--more--> depends on how you wish the script to display itself. The first .js file allows you to display not only the time, but date as well, while the later, just the time. There's a 3k size difference between the two files, just so you know:<br />
<br />
Download <!--more--> ONE of the following two files, and upload to the directory where your webpage resides (click on file, or click with shift key depressed in NS):<br />
<br />
-liveclock.js (6k)-liveclock_lite.js (3k) These files you can Download <!--more--> from <!-- m --><a class="postlink" href="http://www.dynamicdrive.com/dynamicindex6/clock2.htm">http://www.dynamicdrive.com/dynamicindex6/clock2.htm</a><!-- m --><br />
<br />
Should you choose the later, make sure to change the reference in the code of Step 1 to correctly reference its name. Furthermore, both files require some editing inside to configure the clock's style, which you can do through any text editor, such as Windows Notepad.<!--content-->Hi Myst, <br />
Check out the time related category on A1 JavaScripts, there is plenty to choose from and if you have trouble, make a post in the "Client side scripting" forum here and we will help you out.<br />
<!-- m --><a class="postlink" href="http://www.a1javascripts.com/time_related/">http://www.a1javascripts.com/time_related/</a><!-- m --><br />
good luck<!--content-->You could use Javascript, like Ian suggested, but I suggest you use dhtml instead.<br />
It's quite simple, firstly, paste this code in your <HEAD> tag:<br />
<br />
<span id="liveclock" style="position:absolute;left:0;top:0;"><br />
</span><br />
<br />
<script language="JavaScript"><br />
<!--<br />
function show5(){<br />
if (!document.layers&&!document.all)<br />
return<br />
var Digital=new Date()<br />
var hours=Digital.getHours()<br />
var minutes=Digital.getMinutes()<br />
var seconds=Digital.getSeconds()<br />
var dn="AM"<br />
if (hours>12){<br />
dn="PM"<br />
hours=hours-12<br />
}<br />
if (hours==0)<br />
hours=12<br />
if (minutes<=9)<br />
minutes="0"+minutes<br />
if (seconds<=9)<br />
seconds="0"+seconds<br />
//change font size here to your desire<br />
myclock="<font size='5' face='Arial' ><b><font size='1'>Current Time:</font></br>"+hours+":"+minutes+":"<br />
+seconds+" "+dn+"</b></font>"<br />
if (document.layers){<br />
document.layers.liveclock.document.write(myclock)<br />
document.layers.liveclock.document.close()<br />
}<br />
else if (document.all)<br />
liveclock.innerHTML=myclock<br />
setTimeout("show5()",1000)<br />
}<br />
<br />
//--><br />
</script><br />
<br />
Then paste this code in your <BODY> tag:<br />
<br />
<body onLoad="show5()"><br />
<br />
This is basically what eForms said except you don't have to Download <!--more--> anything. It's nice and simply, and will give the time from your user's location. :)<!--content-->Thanks a lot for the help guys!! :) I got it up and running :) Just one more question tho if you dont mind. Where does Javascript grab the info from? Is it from the users/viewers browser?<br />
Thanks a lot again :)<!--content-->Myst,<br />
JS shpuld grab the time from the users computer. I am not sure why Dave suggests against JS for this, either his DHTML sample, or a JS will do for this easily.<!--content-->Dr Web, I know that Javascript would also work, but in my personal opinion dhtml is better to use. :)<!--content-->
 
Back
Top