Scripting: javascript clock

started by Mmiv on Feb 3, 2004 — RSS Feed

Mmiv Mmiv
Posts: 4

Hello to all!

as you will see soon Im giving the first steps in the world of web design.

Im sorry if the question is basic but I really need to learn how to do this.

can somebody help me with this script:

<Script Language="javascript">
<!--

     dt = new Date()
     var stemp;
     var stamp;

     var dt_hour = dt.getUTCHours() ;

     var dt_minute = dt.getUTCMinutes() ;

     var dt_second = dt.getUTCSeconds() ;

     
     

     if (dt_minute < 10)

           dt_minute = '0' + dt_minute ;

     

     if (dt_second < 10)

           dt_second = '0' + dt_second ;
     

     stemp = dt_hour+ ":" + dt_minute + ":" + dt_second ;
   stamp =dt_hour + 7 + ":" + dt_minute + ":" + dt_second ;
     ste=dt_hour
     sta=dt_hour + 7
     
     if (sta > 24)
     stamp= dt_hour - 17 + ":" + dt_minute + ":" + dt_second ;


document.write("<center>"+"<b>"+"<font color=#0099CC size=2>"

if ((ste > 7) && (ste <19))
document.write("<img src='sol.gif'>"+"<br>"
else
document.write("<img src= 'lua.gif'>"+"<br>"
document.write("Hora de Lisboa  "+stemp+"<br>"

if ((sta > 7) && (sta <19))
document.write("<img src= 'sol.gif'>"+"<br>"
else
document.write("<img src= 'lua.gif'>"+"<br>"
document.write("Hora de Jacarta  "+stamp+"<br>"
document.write("</center>"+"</b>"+"</font>"

//-->
</script>

this script probably will shock some of you. I know... I know.. but as I told Im giving the fist steps

The question: the clocks doesn't move and i don't know where to use the setTimout()

can some body help me please?

Thanks

Joe Gillespie Joe Gillespie
Posts: 528

The problem with this script, even it did update, is that it would keep drawing the clocks down the page with every document.write.

This script updates the time in a form text area.


<script language="JavaScript">

<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var clockID = 0;

function UpdateClock() {
  if(clockID) {
     clearTimeout(clockID);
     clockID  = 0;
  }

  var tDate = new Date();

  document.theClock.theTime.value = ""
                                  + tDate.getHours() + ":"
                                  + tDate.getMinutes() + ":"
                                  + tDate.getSeconds();
 
  clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
  clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
  if(clockID) {
     clearTimeout(clockID);
     clockID  = 0;
  }
}

//-->

</script>
<body onload="StartClock()" onunload="KillClock()">
<center><form name="theClock">
<input type=text name="theTime" size=8>
<form></center>

it wouldn't be too difficult to add another time zone.

Mmiv Mmiv
Posts: 4

Thanks a million, I will try!

By the way congratulations for this excellent page and forum

this kinds of things make me a believer in the human race again.  

Mmiv Mmiv
Posts: 4

thanks again i solved my problem!

Jdenny Jdenny
Posts: 65

If you ever put a clock on a web page, then don't make it change every second - it would be very distracting. So take out the seconds, and also then you only need to update the clock each minute not every second...

Instead work out the time left untill the current minute is up, then setTimeout() for that, at whcih point you update the clock text, and set a new time-out for 1 minute.

Maskodok Eko Maskodok Eko
Posts: 171

Jasa SEO Profesional

TOP SEO | Jasa SEO Profesional RajaPoker88.com Agen Texas Poker Dan Domino Online Indonesia Terpercaya IDRPoker.COM Agen Texas Poker dan Domino Online Indonesia Terpercaya POKERSTAR88.com Agen Texas Poker Dan Domino Online Indonesia Terpercaya D

Kokokmas Kokokma Kokokmas Kokokma
Posts: 104

this script probably will shock some of you. I know... I know.. but as I told I�m giving the fist steps

The question: the clocks doesn't move and i don't know where to use the setTimout()

can some body help me please?

Thanks

You know, Sim City Societies had a lot of potential, it was a great concept that was horribly developed and lacked any kind of depth. The idea of individualize buildings functioning independently playing its role in a largely diverse and thriving city.

The new Sim City appears to be the classic Sim City gameplay we saw with SC4, combined with a far better developed version of the Societies concepts. Looking great guys, don't let us down.


You must login to reply