Print Page | Close Window

Clock

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3777
Printed Date: 29 March 2026 at 9:49am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Clock
Posted By: genmud
Subject: Clock
Date Posted: 24 June 2003 at 1:31am

Ok, here is what im trying to do...

im trying to get the Hours, Minutes and Seconds for a dynamic clock that will be off the server time... it will be cool because you can see the time on the server in real time... i am thinking of maybe making this into a mod if i get it finished real quick.




Replies:
Posted By: MorningZ
Date Posted: 24 June 2003 at 8:11am
whats wrong with just spitting out "Now()" ?

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: aero
Date Posted: 24 June 2003 at 8:38am

HI.

If U want a live clock I have on in javascript but it is in danish so U have to changes the names and so on !!

http://www.javacoder.dk:56400/tid.htm - http://www.javacoder.dk:56400/tid.htm

 

the code:

<table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-family: Verdana; font-size: 10px" bgcolor="#ffffff">
          <tr>
            <td width="140">
              <p style="margin-left: 3; margin-top: 2; margin-bottom: 2">
             
<!--webbot bot="HTMLMarkup" startspan -->
<font color="#000000" size="1" face="Verdana">
<SCRIPT LANGUAGE="JavaScript"><!--
var ugeDag = new Array ("SØNDAG","MANDAG","TIRSDAG","ONSDAG","TORSDAG","FREDAG","LØRDAG")
var maaned = new Array ("JAN","FEB","MAR","APR","MAJ","JUN","JUL","AUG","SEP","OKT","NOV","DEC")
var nu = new Date
//-->
document.write( ugeDag[nu.getDay()] + " " + nu.getDate() + ". " + maaned[nu.getMonth()] + " " + nu.getFullYear() )
//-->
</SCRIPT></font>
<!--webbot bot="HTMLMarkup" endspan -->             
             
              </p>
            </td>
            <td width="90">
              <p style="margin-top: 4; margin-bottom: 4"><font color="#000000">&nbsp;-&nbsp;
              KLOKKEN
              ER</font></p>
            </td>
            <td width="100">
              <p style="margin-top: 2; margin-bottom: 2">
             
<script Language="JavaScript">
fon_size=1
fon_famil="Verdana"
fon_color="#000000"
var ns=document.layers?1:0
var ie4=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0

function tab_wri(nam_tab)
{
if(!ns)
 {
 document.write ("<DIV style='position:relative; left:0; top:0; width:"+(fon_size*5+2)+"'>")
 for (i=0; i<10; i++){document.write ("<DIV style='position:absolute; left:0; top:0; visibility:hidden ' ID='tab"+nam_tab+"_n"+i+"'><font face="+fon_famil+" size="+fon_size+" color="+fon_color+">"+i+"</font></DIV>")}
 document.write ("</DIV>")
 }
 else
 {
 document.write ("<ilayer id='ilay"+nam_tab+"'>")
 for (i=0; i<10; i++){document.write("<layer visibility=hide ID='lay"+nam_tab+"_n"+i+"'><font face="+fon_famil+" size="+fon_size+" color="+fon_color+">"+i+"</font></layer>")}
 document.write ("</ilayer>")
 }
}
function see_num(nam_tab,num_tab)
{
if(ie4)
 {
 for(i=0; i<10; i++)
  {
  if(i==num_tab){document.all["tab"+nam_tab+"_n"+num_tab].style.visibility="visible"}
  else{document.all["tab"+nam_tab+"_n"+i].style.visibility="hidden"}
  }
 }
if(ns)
 {
 for(i=0; i<10; i++)
  {
  if(i==num_tab){document.layers["ilay"+nam_tab].document.layers["lay"+nam_tab+"_n"+num_tab].visibility="show"}
  else{document.layers["ilay"+nam_tab].document.layers["lay"+nam_tab+"_n"+i].visibility="hide"}
  }
 }
if(ns6)
 {
 for(i=0; i<10; i++)
  {
  if(i==num_tab){document.getElementById("tab"+nam_tab+"_n"+num_tab).style.visibility="visible"}
  else{document.getElementById("tab"+nam_tab+"_n"+i).style.visibility="hidden"}
  }
 }

}
sec_old="0"
function see_tim()
{
date_=new Date()
wr_s=date_.getSeconds()+""

if(sec_old==wr_s){return}

sec_old=wr_s
wr_h=date_.getHours()+""
wr_m=date_.getMinutes()+""

if (wr_h.length==2){see_num(1,wr_h.charAt(0)); see_num(2,wr_h.charAt(1))}
else{see_num(1,0); see_num(2,wr_h.charAt(0))}

if (wr_m.length==2){see_num(3,wr_m.charAt(0)); see_num(4,wr_m.charAt(1))}
else{see_num(3,0); see_num(4,wr_m.charAt(0))}

if (wr_s.length==2){see_num(5,wr_s.charAt(0)); see_num(6,wr_s.charAt(1))}
else{see_num(5,0); see_num(6,wr_s.charAt(0))}

}

document.write ("<table  border=0 cellpadding=0 cellspacing=0><tr valign=top><td>")
tab_wri(1)
document.write ("</td><td>")
tab_wri(2)
document.write ("</td><td><font face="+fon_famil+" size="+fon_size+" color="+fon_color+">:</font>")
document.write ("</td><td>")
tab_wri(3)
document.write ("</td><td>")
tab_wri(4)
document.write ("</td><td><font face="+fon_famil+" size="+fon_size+" color="+fon_color+">:</font>")
document.write ("</td><td>")
tab_wri(5)
document.write ("</td><td>")
tab_wri(6)
document.write ("</td></tr></table>")

see_tim()
tim_int=window.setInterval("see_tim()",200)

</script>             
             
              </p>
            </td>
            <td width="420">
              <p style="margin-top: 2; margin-bottom: 2">&nbsp;</p>
            </td>
          </tr>
        </table>



Posted By: Boecky
Date Posted: 24 June 2003 at 9:03am
or you can use this code:

<script type="text/javascript">
<!--   // Array ofmonth Names
var monthNames = new Array( "January","February","March","April","May","June","July","August","September","October","November","December");
var now = new Date();
thisYear = now.getYear();
if(thisYear < 1900) {thisYear += 1900}; // corrections if Y2K display problem
document.write(monthNames[now.getMonth()] + " " + now.getDate() + ", " + thisYear);
// -->
</script>


Posted By: MorningZ
Date Posted: 24 June 2003 at 9:06am
unfortunately you guys missed the point that he was trying to show server time, not client side browser time

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 24 June 2003 at 10:08am

Originally posted by MorningZ MorningZ wrote:

whats wrong with just spitting out "Now()" ?

He means the time will increment not just stay static like if you use <%=now()%>...



Posted By: MorningZ
Date Posted: 24 June 2003 at 10:29am

i'm perfectly aware of what he thinks can happen....  have a real time running clock of the server time (if i'm wrong on this, then the topic starter correct me) ....  something that in the Client-Server world known as the internet is not feasible (and my definition/tolerance of feasible might differ from someone else's obviously) since this would require a constant refresh between client on a web browser and the remote server hosting pages..

which if you even remotely had "sorta busy" traffic, this kinda setup would cause way uneccessary strain on the server......



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: aero
Date Posted: 24 June 2003 at 12:41pm

like I wrote

Posted: 24 June 2003 at 8:38am | IP Logged

 

It is running after the server timer !! I have now test it on 3 servers and the time that the script is showing is the same time/clock as the servers !!!

 



Posted By: genmud
Date Posted: 24 June 2003 at 2:47pm
ok, i have this clock, from dynamic drive... it has the time on the client... i just want it to display it on the server, so i need to know how to get the Hours, Minutes and Seconds off the server in ASP. It is really simple(i think) but i know just about zero in ASPvb


Posted By: MorningZ
Date Posted: 24 June 2003 at 2:53pm
you cannot port that Dynamic drvie script from client side (javascript) to server side (asp).. once the server serves the HTML, the connection is lost between both, hence you can have a "dynamic server clock"

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: pmormr
Date Posted: 24 June 2003 at 2:54pm

hour(now())
minute(now())
second(now())



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: genmud
Date Posted: 24 June 2003 at 2:59pm

that definatly wont work, but thanks...

you can make it dynamic, because i said! no, actually you can, because the time adds the numbers off the person's initial time on their clock and just adds numbers, it is possible, and i will eventually work... i just need to know how to get like the Hour and Minutes and Seconds off the server, im not asking anything tooo hard.



Posted By: MorningZ
Date Posted: 24 June 2003 at 3:00pm
neither will anything else.....

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: pmormr
Date Posted: 24 June 2003 at 3:05pm
why don't you just use straight up asp and put in <%= now()%> in your script?

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: MorningZ
Date Posted: 24 June 2003 at 3:21pm

wow, i must be typing in "invisible font" today, lol

he's obviosuly trying to do something like this:
http://www.dynamicdrive.com/dynamicindex6/lcdclock.htm - http://www.dynamicdrive.com/dynamicindex6/lcdclock.htm

but show the running server time, not the client's time... which "isn't possible" in server side script since once the page content gets served to the client, bam, the connection between the two computers is over with



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: genmud
Date Posted: 24 June 2003 at 4:05pm
you are wrong... if you can format the thing so that you can get the Hours, Minutes and Seconds i guarentee that i could get it!


Posted By: pmormr
Date Posted: 24 June 2003 at 4:50pm

just put

<%
   Response.Write(hour(now()) & ":")
   If minute(now()) < 10 then
      response.write ("0" & minute(now()) & " " & second(now()))
   Else
      Response.write (minute(now()) & " " & second(now()))
   End If
%>



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: pmormr
Date Posted: 24 June 2003 at 5:03pm
but that clock won't update every second... only when you hit refresh

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: MorningZ
Date Posted: 24 June 2003 at 10:12pm

Originally posted by genmud genmud wrote:

you are wrong... if you can format the thing so that you can get the Hours, Minutes and Seconds i guarentee that i could get it!

am i now?  lesse.. i recall a reply on this post by you: "i dont know much ASP" or something along those lines.......

its glaringly obvious you have absolutely zero idea "how" server script works, otherwise you'd understand that the only way to have a server-side update is to refresh the page (read: VERY server intensive and unusable for your visitors)

but what do i know, i've only coded ASP for a living for 4 years now, i dont know jack crap i guess



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: TYSON
Date Posted: 25 June 2003 at 7:07am
lol , Give up MorningZ, this could go on for ages.

-------------
http://www.fuo-motorsports.com/ - http://www.fuo-motorsports.com/


Posted By: pmormr
Date Posted: 25 June 2003 at 10:04am
can you put asp inside the java script?

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: MorningZ
Date Posted: 25 June 2003 at 11:29am

ASP script/code/whatever-you-wish-to-call-it runs on the server......

Now whatever it does, talk to a database, manipulate a local file, add 1+1, grab the server time, count to 1000 and do the hokey pokey......  whatever it does... the end result is HTML sent to the client (the computer/browser/human) on the other side of the connection who made the request....   once it delivers the HTML, the web server and client are through talking..... 

Now while you can have ASP "used in Javascript", be aware that the only time it'll do anything is when the page is rendered..

so...

in "test.asp" you have, and this is just a huge super slimmed down example:

<script language="javascript">
function ShowTime() {
 var CurrentTimeAsString = '<%= Now() %>';
}
</script>

if you "view" that page, you'd see something like:

<script language="javascript">
function ShowTime() {
 var CurrentTimeAsString = '6/25/2003 1:18:58 PM';
}
</script>

and at this point, ASP has done its job, page is rendered and delivered to the client, it no longer has a need to comminicate with the client, so the connection is severed

and this doesn't just go for ASP, it goes for PHP, and CF, and any other server-side language

Javascript on the other hand DOES run "real time" on the client.. so it has the ability to constantly update the page with something like, say, a clock....... so thats where the scripts on Dynamic Drive come in.... all that is pulling the time from the client and is in the realm of what it has access to (locally on the client's browser), it has abolutely zero access to the server at this post

Now this isn't saying that one couldn't write some code that "starts" from the "Now()" provided by the server, and then every second increments that initial time given by the server and constantly updates the page, but understand that the time will be off more and more as the javascript takes time to run



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: pmormr
Date Posted: 25 June 2003 at 3:27pm
i see what you're talking about... the asp script takes time to run. and then the javascript takes time to run so by then you have a clock off by about 2 seconds...

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net