Jump to content

Java Clock


Recommended Posts

Here is some Javascript code for a clock that gets the time for the part of the world you live in.

<HTML>
<body onload = "tick()" text="#FFFFFF" bgcolor="#000000" >
<script type = "text/javascript" >
<!--

function tick(){
var now = new Date();
var offset = now.getTimezoneOffset();
var msg;
switch(offset){
case 240 : msg = "East Coast"; break;
case 300 : msg = "Central"; break;
case 360 : msg = "Mountain"; break;
case 420 : msg = "Pacific"; break;
default : msg = "all";
}
var hh = now.getHours(); if( hh <= 9 ) hh = "0" + hh;
var mn = now.getMinutes(); if(mn <= 9 ) mn = "0" + mn;
var ss = now.getSeconds(); if( ss <= 9 ) ss = "0" + ss;
var tt = hh + ": " +mn+ ": " + ss;
document.f.clock.value = tt;
window.setTimeout( "tick()", 1000 );
}

//-->
</script>
<form name = "f" >
<font color="#FF0000">
<input name= "clock" type = "text" SIZE = "10"></font> Current Time</form>
</body>
</HTML>

:) My first Javascript code

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...