JavaScript to implement the method of adding days in a given time _javascript skills

Source: Internet
Author: User
Tags time and date

The examples in this article describe how JavaScript implements the number of days added for a given time. Share to everyone for your reference, specific as follows:

/** * Time Add processing function * @param date time to calculate (xxxx-xx-xx) * @param number of days to add (integer)/function calcudate (date, plusdays) {VA
  R Datearray = Date.split ("-");
  var year = +datearray[0];
  var month = +datearray[1];
  var day = +datearray[2];
  var oriday = day; var secondmonthdays = ((year%4 = = 0 && year%100!== 0) | | | year%400 = 0)?
  29:28;
    while (plusdays>0) {oriday = Day Day = = Plusdays; Switch (month) {case 4:case 6:case 9:case 11:if (Day >) {plusdays-= (
          30-oriday) +1;
          month++;
        Day = 1;
        else {plusdays = 0;
      } break;
          Case 2:if (Day > Secondmonthdays) {plusdays-= (secondmonthdays-oriday) +1;
          month++;
        Day = 1;
        else {plusdays = 0;
      } break;
          Default:if (Day >) {plusdays-= (31-oriday) +1;
          Day = 1;
        month++;
    } else {      plusdays = 0;
      } if (month>12) {month = 1;
    year++;
} Return to Createtimestring (year, month, day);

 }

Of course, in addition to this approach, there are other, similar to the new date parameters such as the solution, which is a kind of

Read more about JavaScript time and date operations interested readers can view the site: "JavaScript time and date Operation Skills Summary"

I hope this article will help you with JavaScript programming.

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.