JS gets the current time (time changed)

Source: Internet
Author: User

<MCE: script language = "JavaScript"> <! -- <Br/> // define a tick function to obtain the system time <br/> function tick () <br/>{< br/> var year, month, day, hours, minutes, seconds, AP; <br/> var intyear, intmonth, intday, inthours, intminutes, intseconds; <br/> var today; <br/> today = new date (); <br/> intyear = today. getyear () + 1900; <br/> intmonth = today. getmonth () + 1; <br/> intday = today. getdate (); <br/> inthours = today. gethours (); <br/> intminutes = today. getminutes (); <br/> intseconds = today. getseconds (); <br/> // obtain the hours of the system time <br/> If (inthours = 0) <br/>{< br/> hours = inthours + ":"; <br/> ap = ""; <br/>}< br/> else if (inthours <12) <br/>{< br/> hours = inthours + ":"; <br/> ap = "Morning"; <br/>}< br/> else if (inthours = 12) <br/>{< br/> hours = inthours + ":"; <br/> ap = "Noon "; <br/>}< br/> else <br/> {<br/> inthours = intHours-12; <br/> hours = inthours + ":"; <br/> ap = "PM"; <br/>}< br/> // obtain the system time score <br/> If (intminutes <10) <br/>{< br/> minutes = "0" + intminutes + ":"; <br/>}< br/> else <br/> {<br/> minutes = intminutes + ":"; <br/>}< br/> // obtain the system time in seconds <br/> If (intseconds <10) <br/>{< br/> seconds = "0" + intseconds + ""; <br/>}< br/> else <br/> {<br/> seconds = intseconds + ""; <br/>}< br/> timestring = intyear + 'Year' + intmonth + 'month' + intday + 'day' + hours + minutes + seconds + AP; <br/> document. getelementbyid ("Clock "). innerhtml = timestring; <br/> // execute the tick function once every 0.1 seconds. <br/> window. setTimeout ("tick ()", 100); <br/>}< br/> window. onload = tick; <br/> // document. getelementbyid ("Clock "). innerhtml = timestring; <br/> // --> </MCE: SCRIPT> <br/> the DIV in the body is: <Div id = "Clock"> </Div

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.