Javascript Study Notes (3) show the code at that time _ basic knowledge-js tutorial

Source: Internet
Author: User
The main purpose is to familiarize yourself with the date object in javascript. The html code is as follows:

The Code is as follows:




The javascript code is as follows: Time Display format: 12:09:34 on Tuesday

The Code is as follows:


Function startTime (){
Try {
Var today = new Date ();
Var year = today. getFullYear ();
Var month = checkNum (today. getMonth () + 1 );
Var date = checkNum (today. getDate ());
Var day = today. getDay ();
Var hour = checkNum (today. getHours ());
Var minute = checkNum (today. getMinutes ());
Var second = checkNum (today. getSeconds ());
Switch (day ){
Case 1:
Day = "1 ";
Break;
Case 2:
Day = "2 ";
Break;
Case 3:
Day = "3 ";
Break;
Case 4:
Day = "4 ";
Break;
Case 5:
Day = "5 ";
Break;
Case 6:
Day = "6 ";
Break;
Case 7:
Day = "day ";
Break;
}
Var fullTime = year + "-" + month + "-" + date + "" + "Week" + day + "+ hour +": "+ minute + ": "+ second;
Document. getElementById ("showTime"). innerHTML = fullTime;
SetInterval ('starttime () ', 1000 );
} Catch (e ){
Alert (e. description );
}
}
Function checkNum (num ){
If (num <10 ){
Num = "0" + num;
}
Return num;
}

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.