A Clock Script : Time « Development « JavaScript DHTML






A Clock Script


<HTML>
<HEAD>
<TITLE>Clock</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
function dateTime() {
 var now = new Date();
 var result = now.toLocaleString();
 var tzOffset=-now.getTimezoneOffset()/60;
 if(tzOffset<0) 
    result += " (GMT "+tzOffset+" hours)";
 else 
    result += " (GMT +"+tzOffset+" hours)";
 return result;
}
function tick() {
 document.forms[0].clock.value=dateTime()
 setTimeout("tick()",1000)
}
// --></SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT NAME="clock" TYPE="TEXT" SIZE="50"
 VALUE="&{dateTime()};">
</FORM>
<SCRIPT LANGUAGE="JavaScript"><!--
tick()
// --></SCRIPT>
</BODY>
</HTML>

           
       








Related examples in the same category

1.Formats the current hour and displays it in a static or dynamic way
2.Times Table
3.Update Time per second
4.Time: hour, minutes, and seconds.
5.Display the Current Time in status bar
6.Creating a Clock Object and Displaying the Results on the Page
7.Morning or Evening
8.Time value
9.Get the current time and then extract the hours, minutes and seconds