一、某月第一天
/*** 获取某年某月的第一天*/public static String getFisrtDayOfMonth(int year,int month){Calendar cal = Calendar.getInstance();//设置年份cal.set(Calendar.YEAR,year);//设置月份cal.set(Calendar.MONTH, month-1);//获取某月最小天数int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);//设置日历中月份的最小天数cal.set(Calendar.DAY_OF_MONTH, firstDay);//格式化日期SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");return sdf.format(cal.getTime());}
}
二、某月最后一天
/*** 获取某月的最后一天*/public static String getLastDayOfMonth(int year,int month){Calendar cal = Calendar.getInstance();//设置年份cal.set(Calendar.YEAR,year);//设置月份cal.set(Calendar.MONTH, month-1);//获取某月最大天数int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);//设置日历中月份的最大天数cal.set(Calendar.DAY_OF_MONTH, lastDay);//格式化日期SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");return sdf.format(cal.getTime());}