JS Real-time Acquisition system Current time instance code _javascript skill

Source: Internet
Author: User

(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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.