When using JS to draw a working calendar, you need to use JS to calculate the total number of days of the specified month
On the Internet to find some methods, are more cumbersome, and later brainwave, think of a lazy way to share
First, the principle analysis
To get the number of days in a month, just take the date to the last day of the month.
Around this idea, flexible call setmonth (), GetMonth (), SetDate (), GetDate (), calculate the required date
Second, the Code implementation
function Getmonthlength (date) { new Date (date) // set Date to next month D.setmonth (D.getmonth () +1) d.setdate ('1') // get the last day of the Month D.setdate (D.getdate ()-1) return d.getdate ()}
Three, a little pain in the face
In less than an hour, he was beaten to the face by a man.
There are more simple ways to do it:
New 0). GetDate ()
When you create a time object using new Date (), if date is passed in 0, you can get the date from the last day directly through GetDate ()
JavaScript calculates the number of days in a specified month