JS gets one months maximum days
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 the first one months of the last day ("XX" month's maximum value is 69, digression),
When you pass in the "XXXX/XX/1" (number 1th), the date is "XX" month after the first day of one months (oneself understand)
If you pass in "1999/13/0", you will get "1998/12/31". And the biggest advantage is that when you pass in "xxxx/3/0", will get XXXX year February of the last day, it will automatically determine whether it is a leap year to return 28 or 29, do not judge yourself,
So, we want to choose how many days the choice of year, only need
var temp=new Date ("Select year/Select Month +1/0");
return temp.getdate ()//Maximum days
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 ();
}
Use JavaScript to get the number of days for a month as follows:
Goal: Get 2014/April days
Constructs a Date object:
var day = new Date (2014,4,0);
Get days:
var daycount = Day.getdate ();
Description: OK, the number of days you want has come out. GetDate () is the last day of acquisition, the number of days of the month Note: when we construct a Date object, 4 is actually constructed in May, because the month starts at 0. The third number of 0 days, the minimum requirement is 1th, smaller than 1th, it will be the last day of your March.