Displays the time in the Web page in real-time, not only can give the Web page Tim, but also can facilitate the viewer to grasp the current time, in order to improve the speed of web site development, can be encapsulated in a separate function of the main code, in need of direct call and I for the demonstration, directly written in the main page, to facilitate everyone to watch
(1): First with JS to write real-time display system time function Clockon () only a parameter bgclock, used to specify the display for the conversion of the name of the <div> tag, no return value, you can change the function of Web site development in the JS file, in order to reuse The code is as follows:
Copy Code code as follows:
<script>
function Clockon (bgclock)
{
var now = new Date ();
var year = Now.getyear ();
var month = Now.getmonth ();
var date = Now.getdate ();
var day = Now.getday ();
var hour = now.gethours ();
var minu = Now.getminutes ();
var sec = Now.getseconds ();
var week;
month = month+1;
if (month<10) month= "0" +month;
if (date<10) date= "0" +date;
if (hour<10) hour= "0" +hour;
if (minu<10) minu= "0" +minu;
if (sec<10) sec= "0" +SEC;
var arr_week = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
week = Arr_week[day];
var time = "";
time = year+ "year" +month+ "month" +date+ "Day" +week+ "" +hour+ ";" +minu+ ";" +sec;
if (document.all)
{
bgclock.innerhtml= "[" +time+ "]"
}
var timer = settimeout ("Clockon (Bgclock)", 200);
}
</script>
(2): Call in the <body> onload event of the page and place the DIV tag code where you want to display it:
Copy Code code as follows:
<body onload= "Clockon (bgclock)" >
<div id= "Bgclock" class= "Word_green" ></div>
</body>