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

Simple Javascript (local time clock) Trouble =(

Status
Not open for further replies.

TypeIII

Technical User
Dec 26, 2003
5
HK
Ok this is like the dumbest, yet strangest thing (to me anyway)... So I have the following script in an HTML file:

<script language="JavaScript">

<!--

document.write("<span id='clock'></span>");

var now,hours,minutes,timeValue;

function showtime(){

now = new Date();

hours = now.getUTCHours();

hours -= 2

if (hours>=24)

{
hours-=24
}

minutes = now.getUTCMinutes();

timeValue = hours + " :";

timeValue += ((minutes < 10) ? " 0" : " ") + minutes;

clock.innerHTML = timeValue;

setTimeout("showtime()",100);

}

showtime();

//-->

</script>

Ok, no big deal... Then I realized that sometimes when I travel to regions with GMT being a negative value, the clock could be showing a negative number sometimes, so I tried to fix it by inserting another IF statement, no go... Elseif, no go... The clock wouldn't show at all. What am I doing wrong?
 
Show an example of the non-working script.

By the way, elseif is not javascript. You would need else if (with a space).

--Dave
 
Actually I sorted out the problem. Stupid me, I misspelled left out the "s" in my variable hours. =) DOH! Don't you hate that. Heehee but thanks for reading guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top