JS implementation calendar To obtain a specified number of weeks and days of the week sample sharing

Source: Internet
Author: User
Tags date1 weeks from date

  Write a simple calendar. In the text box, enter the date you want to find, the program can calculate the day of the Year in the week, and can determine what the day is the week, the need for friends can refer to the following

Should be interactive, choose JS to achieve, is also a pair of programming for the preliminary. I'll have the display part written in HTML, click on the button to trigger the event function is check ();     Code is as follows: function Oncheck () {  var year = document.getElementById (" Year "). Value; Gets the text box "year" var theyear =year * 1; Convert to Number type//alert (theyear); Gets the month value   var month = document.getElementById ("month");  var Index1=month.selectedindex; var themonth = Month.options[index1].value; Get month value   var day = document.getElementById (' Day ');  var index2=day.selectedindex;  var theday = Day.options[index2].value;  //Input value judgment section ...//Call core function days (theyear,themonth,theday); }       Core functions days are as follows:      The code is as follows: function days (year,month,day) {      var day = 0;  //to change date to day of year    //cumulative month days     for (var i = 1; i < month i++) {    switch (i) {   //semi-rotary situation plus   Case 1:     3:     Case 5:     Case 7:     Case 8:     Case:     case 12: {    days + +     break;    }    //The situation of the Luna plus     Case 4:   &N Bsp Case 6:     Case 9:     case 11:{    =     break;    } &nbsp ;  //February, according to the year type to add     case 2:{        if (isleapyear) {      &NBSP ; days = 29; Leap year add        }         else {        days + +   &N Bsp    }     break;    }    }} day = day * 1; Days = day;  //the sum of days of the month plus days   var date0 = new Date (year,0,1);   The first day of the year is the Week//  alert (Date0.getday ());     var date1 = new Date (year,month-1,day); Format Date values, 0-11 represents January-December;//  Alert (days + date0.getday () +6)/7);     var nthofweek = Math.floor (days + date0.getday () +6)/7);  //Down//  alert (Nthofweek);     var today = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");     //day.getday (); One of the one weeks from date 0 is Sunday       Alert ("The date is the" +days+ "Day N" + "    is the" +nthofweek+ "Week" +today[date1.getday ()] "of the year; A number of unexpected errors were encountered during the       debugging process. If the mismatch of types brings about computational errors, such as rounding of numbers; With the help of his teammates, he is responsible for auditing and assisting in catching bugs, and I am responsible for implementing and coding; In the last step, in the test of the input value, We are very good to help each other, analysis of different input, covering a variety of possible accidents, quickly completed the completion of the function; The following is the code that determines whether the input value is allowed:     Code as follows: if (isNaN (theyear) | | theyear < 0) {  Alert ("Input is incorrect, please re-enter");   return;}   if ((Themonth = 2 && theday > && isleapyear (theyear)) | | (Themonth = 2 && theday > &&!isleapyear (theyear)) {  Alert ("Input is incorrect, please re-enter");   return;}     if ((Themonth = 4 | | themonth = 6 | | themonth = 9 | | themonth = one) && Theday =) {  AL ERT ("Input is incorrect, please re-enter");   return; }   

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.