1. Implement source code
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>JavaScript gets the last day of a certain month</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> <script type="text/javascript"> /** * Gets the last day of a certain month in a certain year*/ function getLastDayOfMonth(year,month) { //Get the first day of the month of this year var date = new Date(year,month-1,'01'); //Set the date.setDate(1); //Set the month date.setMonth(date.getMonth() + 1); //Get the last day of this month cdate = new Date(date.getTime() - 1000*60*60*24); //Print the last day of a certain month alert(cdate.getFullYear()+"year"+(Number(cdate.getMonth())+1)+"the date of the last day of the month: "+cdate.getDate()+"day"); //Return result return cdate.getDate(); } </script> </head> <body> <input type="button" value="get the last day of a certain month" onclick="getLastDayOfMonth(2014,6)"/> </body> </html>2. Achieve the results