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