JavaScript shows time, time is still moving! Not a static effect!
Demo Address: http://www.ijavascript.cn/tools/jsdemo/320/time.htm
Functions time () defines a function. Www.120hrb.com
{if (!document.layers&&!document.all)
return because the IE and Netscape to the JavaScript explanation different, causes the browsing effect to be different, therefore must write the code separately. This sentence determines the browser used by the user, if neither, returns.
var timer=new date () defines a new variable, named Timer, for a new Date object.
var hours=timer.gethours ()
var minutes=timer.getminutes ()
var seconds=timer.getseconds () Defines 3 variables to get the current "hour", "Minute", "second" value.
var noon= "AM" if (hours>12)
{noon= "PM" hours=hours-12}
if (hours==0)
HOURS=12 defines a variable named "noon" when the number of hours is greater than 12 o'clock, its value is PM, the value is reduced by 12, and the value is am when the number of hours is less than 12 o'clock.
if (minutes<=9)
minutes= "0" +minutes
if (seconds<=9)
seconds= "0" +seconds if the number of minutes or seconds is less than 9, add a "0" to the front.
myclock= "" +hours+ ":" +minutes+ ":" +seconds+ "" +noon+ "with a new variable to" hours, minutes, seconds "together.
if (document.layers)
{document.layers.position.
document.write (Myclock)
Document.layers.position.document.close ()} If the browser is Netscape, the output is Myclock, and the code for IE stops executing.
else if (document.all) www.hrbfkyy120.com
Position.innerhtml=myclock Otherwise, the browser is IE, on the output myclock.
The SetTimeout ("Time ()", 1000) every 1000 milliseconds, invokes the function of the moment, that is, one second.
When the "Time ()" page is loaded, the onload= () function is called.
The following is the simplest way to display a date
JavaScript display time