SoFunction
Updated on 2025-03-10

A relatively simple JavaScript script that displays time in real time Correction version

JavaScript displays time, time is still moving! Not a static effect!
function Time() Define a function.
{ if (!&&!) 
return: Since IE and Netscape have different interpretations of JavaScript, the browsing effect is different, so you have to write code separately. This sentence determines the browser the user is using. If neither is it, return.
var timer=new Date() Defines a new variable with the name timer, which is an object with a new Date.
var hours=() 
var minutes=() 
var seconds=() Define 3 variables respectively to obtain the current values ​​of "hours", "minutes", and "seconds".
var noon="AM" if (hours>12) 
{ noon="PM" hours=hours-12 } 
if (hours==0) 
hours=12 Define a variable named "noon". When the number of "hours" is greater than 12, its value is PM, and the obtained value is reduced by 12; when the number of "hours" is less than 12, its value is AM.
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" in front of it.
myclock="<font color=blue>" +hours+":"+minutes+":" +seconds+" "+noon+"</b></font>" Use a new variable to combine "hours, minutes, seconds".
if () 
{ . 
(myclock) 
() } If the browser is Netscape, output myclock, and the code used for IE will be stopped.
else if () 
=myclock  Otherwise, if the browser is IE, myclock will be output.
setTimeout("Time()",1000) Every 1000 milliseconds, the Time function is called, that is, it moves once in a second.
onload="Time()" When the page is loaded, the Time() function is called.

[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]


The following is the easiest way to display dates

[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]