Post by admin™ on Sept 28, 2004 11:24:20 GMT -5
Clock
This is the simple clock example that can be used by any one in their website. It uses a combination of functions, forms and IF statements for the right time to be shown.
<form name="Tick">
<input type="text" size="12" name="Clock">
</form>//1
function show() //2
{
var Digital=new Date() //3
var hours=Digital.getHours() //4
var minutes=Digital.getMinutes() //5
var seconds=Digital.getSeconds()//6
var dn="AM" //7
if (hours>12) //8
{
dn="PM" //a little loop occurs declaring dn as PM when it is past 12
hours=hours-12 //9
} //10
if (hours==0)
hours=12 //11
if (minutes<=9)
minutes="0"+minutes //12
if (seconds<=9)
seconds="0"+seconds //13
document.Tick.Clock.value=hours+":"+minutes+":"
+seconds+" "+dn //14
setTimeout("show()",1000) //15
} //16
show() //17
//1=this is the simple form that is set up to show the clock and the size that it is
//2=a simple function called show is set up
//3=the variable digital is set up and is given the value of the current date
//4=here the variable hours is given the value of the current hour from the computer clock
//5=here the variable minutes is assigned the value of the current minutes from the computer clock
//6=here again the variable seconds is given the current time in seconds from the computer clock
//7=here the variable dn is given the value of AM as in time
//8=if the time is above 12
//9=this is so the hours written out is in 12-hour format, instead of the default 24-hour format
//10=the loop can now end
//11=this is so the hours written out when hours=0 (meaning 12a.m) is 12
//12=this is just so that the minutes do not stop at 9 but continue on
//13=this is just so that the seconds do not stop at 9 but continue to say 10 or 20 and start again
//14=the time can now be shown with all the conversions taken place
//15=this just makes sure that the function show is run every second so the time is consistent
//16=the function is ended
//17=the function is called up and can now run
This is quite a tricky coded example and in some cases you may find it hard to understand at first but it soon becomes clear. It may be difficult for you to copy this code to your own websites because of an error that exists, however if you do manage to crack it then please contact me. You may however wish to copy this file by going to View Source and copying the entire code.
Back to the contents page
This code was taken from the:
Mike Van Kleef website which is no longer available as he has left the university and his address is no longer available
This is the simple clock example that can be used by any one in their website. It uses a combination of functions, forms and IF statements for the right time to be shown.
<form name="Tick">
<input type="text" size="12" name="Clock">
</form>//1
function show() //2
{
var Digital=new Date() //3
var hours=Digital.getHours() //4
var minutes=Digital.getMinutes() //5
var seconds=Digital.getSeconds()//6
var dn="AM" //7
if (hours>12) //8
{
dn="PM" //a little loop occurs declaring dn as PM when it is past 12
hours=hours-12 //9
} //10
if (hours==0)
hours=12 //11
if (minutes<=9)
minutes="0"+minutes //12
if (seconds<=9)
seconds="0"+seconds //13
document.Tick.Clock.value=hours+":"+minutes+":"
+seconds+" "+dn //14
setTimeout("show()",1000) //15
} //16
show() //17
//1=this is the simple form that is set up to show the clock and the size that it is
//2=a simple function called show is set up
//3=the variable digital is set up and is given the value of the current date
//4=here the variable hours is given the value of the current hour from the computer clock
//5=here the variable minutes is assigned the value of the current minutes from the computer clock
//6=here again the variable seconds is given the current time in seconds from the computer clock
//7=here the variable dn is given the value of AM as in time
//8=if the time is above 12
//9=this is so the hours written out is in 12-hour format, instead of the default 24-hour format
//10=the loop can now end
//11=this is so the hours written out when hours=0 (meaning 12a.m) is 12
//12=this is just so that the minutes do not stop at 9 but continue on
//13=this is just so that the seconds do not stop at 9 but continue to say 10 or 20 and start again
//14=the time can now be shown with all the conversions taken place
//15=this just makes sure that the function show is run every second so the time is consistent
//16=the function is ended
//17=the function is called up and can now run
This is quite a tricky coded example and in some cases you may find it hard to understand at first but it soon becomes clear. It may be difficult for you to copy this code to your own websites because of an error that exists, however if you do manage to crack it then please contact me. You may however wish to copy this file by going to View Source and copying the entire code.
Back to the contents page
This code was taken from the:
Mike Van Kleef website which is no longer available as he has left the university and his address is no longer available