Incoming year and month, get to the first day of the month:
/*** Get the first day of the specified month *@paramYear *@paramMonth *@return */ Public StaticString GetFirstDayOfMonth1 (intYearintmonth) {Calendar cal=calendar.getinstance (); //Set YearCal.set (calendar.year, year); //Set MonthCal.set (Calendar.month, month-1); //get the minimum number of days in a month intFirstDay =Cal.getminimum (calendar.date); //set the minimum number of days for a month in a calendarCal.set (Calendar.day_of_month,firstday); //formatted DateSimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd"); returnSdf.format (Cal.gettime ()); }
Incoming year and month, get to the last day of the month:
/*** Get the last day of the specified month *@paramYear *@paramMonth *@return */ Public StaticString GetLastDayOfMonth1 (intYearintmonth) {Calendar cal=calendar.getinstance (); //Set YearCal.set (calendar.year, year); //Set MonthCal.set (Calendar.month, month-1); //get the maximum number of days in a month intLastday =Cal.getactualmaximum (calendar.date); //set the maximum number of days for a month in a calendarCal.set (Calendar.day_of_month, Lastday); //formatted DateSimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd"); returnSdf.format (Cal.gettime ()); }
Java-through the years, get to the first day of the month and the last day