javascript--Get current system time

Source: Internet
Author: User
Tags time and seconds

Output Current system time:

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Get current system time</title>    <Script>window.onload= function(){        //Get BODY element        varObody=document.body; //set the timer to execute the function once every 1 secondssetinterval (Fntime, +); //the page executes the DATE function before it is loaded, preventing white space from appearing when refreshedFntime (); //turn a number less than two digits into a two-bit number        functiontodouble (num) {returnNum< Ten ? '0' +Num:"' +num;        }; //Time function Body        functionFntime () {//Get Date Object            varmydate= NewDate (); //get month day time seconds            variyear=mydate.getfullyear (); varImonth=Mydate.getmonth ()+1; varIday=Mydate.getday (); varIhour=mydate.gethours (); varImin=mydate.getminutes (); varISec=mydate.getseconds (); varStr= "'; //The iday value corresponds to the subscript of the Iweek array to get the week            varIweek= ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; //saves the current month and day time and seconds in the string strStr= 'today is:' +iyear+ 'years' +Imonth+ 'Month' +Iweek[iday]+ ',' +todouble (Ihour)+ ':' +todouble (imin)+ ':' +todouble (ISEC); //output the time directly to the body page to displayobody.innerhtml=str;    };    }; </Script></Head><Body>    </Body></HTML>

Note the point:
1) getMonth () return value is 0--11

When you get the month, you have to add 1 to the back, or you get the month of the last one months.

2) GetDay () Return day of the week (0--6)
0--> Sunday
1--> remembered a
2--> Tuesday
3--> Wednesday
4--> Thursday
5--> Friday
6--> Saturday
Thought: Put the array iweek = [' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '], and use the value of the array subscript with getday () to take the value

3) Detail problem: The representation of one number in two digits

Judging by ToDouble function Trinocular operation or if Else

javascript--Get current system time

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.