Js real-time acquisition of the current system time instance code

Source: Internet
Author: User

(1): First, write the function clockon () for real-time system time display in JS. There is only one parameter bgclock, which is used to specify the name of the <div> flag used for display after conversion. No return value is returned, during website development, you can save the function modification in the JS file to reuse the Code as follows:

Copy codeThe Code is 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 the <body> onload event on the page and place the div tag code in the area to be displayed:

Copy codeThe Code is 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.