Javascript displays the current system time code

Source: Internet
Author: User

1. Add the following code to Copy codeThe Code is as follows:
<Script language = JavaScript>
Var timerID = null;
Var timerRunning = false;
Function stopclock (){
If (timerRunning)
ClearTimeout (timerID );
TimerRunning = false ;}
Function startclock (){
Stopclock ();
Showtime ();}
Function showtime (){
Var now = new Date ();
Var hours = now. getHours ();
Var minutes = now. getMinutes ();
Var seconds = now. getSeconds ()
Var timeValue = "" + (hours> = 12 )? "Afternoon": "Morning ")
TimeValue + = (hours> 12 )? Hours-12: hours)
TimeValue + = (minutes <10 )? ": 0": ":") + minutes
TimeValue + = (seconds <10 )? ": 0": ":") + seconds
Document. clock. thetime. value = timeValue;
TimerID = setTimeout ("showtime ()", 1000 );
TimerRunning = true ;}
</SCRIPT>

2. Add the following code to <body>:
Onload = startclock ()
3. Insert the following code at the display time. We recommend that you use table positioning.
[Code]
<Form name = clock>
<Input name = thetime style = "font-size: 9pt; color: #000000; border: 0" size = 12>
</Form>
// Only obtain the function of the current system date
<Script language = "JavaScript" type = "text/javascript">
Document. write (new Date (). getYear () + "-" + (new Date (). getMonth () + 1) + "-" + new Date (). getDate ());
</Script>
Http://www.jb51.net/article/12786.htm

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.