How to display the current system time in real time on a jsp page

Source: Internet
Author: User

JS Code
Copy codeThe Code is as follows:
<Script language = "javascript">
Function real‑ime (clock ){
Var now = new Date (); // create a Date object
Var year = now. getFullYear (); // obtain the year
Var month = now. getMonth (); // obtain the month
Var date = now. getDate (); // get the date
Var day = now. getDay (); // obtain the week
Var hour = now. getHours (); // get the hour
Var minu = now. getMinutes (); // get minutes
Var sec = now. getSeconds (); // get seconds
Month = month + 1;
Var arr_week = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Var week = arr_week [day]; // week for retrieving Chinese Characters
Var time = year + "year" + month + "month" + date + "day" + week + "" + hour + ":" + minu + ":" + sec; // combine the system time
Clock. innerHTML = time; // display the system time
}
Window. onload = function (){
Window. setInterval ("realeffecime (clock)", 1000); // obtain and display the system time in real time
}
</Script>

Add id = "clock" to the display area, for example, <td id = "clock"/>

Related Article

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.