Javascript obtains the number of days in a month.

Source: Internet
Author: User

The new date ("xxxx/XX/xx") Construction Method in Javascript has a wonderful effect. When you input "xxxx/XX/0" (0) the date obtained is the last day of the previous month of the month (the maximum value of the Month of "XX" is 69. If "" is input ", "" is displayed ". The biggest benefit is that when you input "xxxx/3/0", you will get the last day of January 1, February, xxxx, And it will automatically determine whether the current year is a leap year to return 28 or 29, you don't have to judge it by yourself. It's too convenient !! Therefore, if we want to select the year and the number of days of the month, we only need

VaR d = new date ("Select Year/select month + 1/0 ");

Alert (D. getdate ());

The getdaysinonemonth (year, month) method written in Javascript is as follows:

Function getdaysinonemonth (year, month ){
Month = parseint (month, 10) + 1;
VaR d = new date (year + "/" + month + "/0 ");
Return D. getdate ();
}

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.