The general practice is to determine the number of months, and then decide how many days (generally with switch), if it is February, but also to determine whether the year of choice is a leap years, and then decide whether it is 28 days or 29 days. This is a very regular practice, and also very logical.
However, if it is to achieve the purpose, it is not so troublesome. JS inside of the new date ("Xxxx/xx/xx") the date of the construction method has a beauty, when you pass in the "xxxx/xx/0" (number No. 0), the date is the "XX" month of the first one months of the last day ("XX" month's maximum value is 69, digression), if the incoming "1999/13/0", will get "1998/12/31". And the biggest advantage is when you pass in "xxxx/3/0", will be xxxx year February the last day, it will automatically determine whether it is a leap year to return 28 or 29, do not own judgment, too convenient!! So, we want to choose how many days the choice of year, only need
Copy Code code as follows:
var temp=new Date ("Select year/Select Month +1/0");
Alert (Temp.getdate ());
It's okay, isn't it convenient? Check, you can also use this method.
The following is a getdaysinmonth (year, Month) method written using JS to obtain the number of days of a certain month:
Copy Code code as follows:
function Getdaysinmonth (year,month) {
month = parseint (month,10) +1;
var temp = new Date (year+ "/" +month+ "/0");
return Temp.getdate ();
}
Here is the simple test code:
<script> function Getdaysinmonth (year,month) {month = parseint (month,10) +1; var temp = new Date (year+ "/" +month+ "/0"); return Temp.getdate (); Alert (Getdaysinmonth ("2009", "11")); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]