获取某年某月的最后一天和第一天
public static String getFirstAndLastDay(int year, int month) {
String firstAndLastDay = "";
if(year < 0 || month < 1) {
return "fail";
}
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
//Calendar月份从0开始
cal.set(Calendar.MONTH, month - 1);
//方便查看
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//获取year年month月的开始一天
int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
//设置Calendar为指定月份的第一天
cal.set(Calendar.DAY_OF_MONTH, firstDay);
//指定月份第一天
firstAndLastDay += sdf.format(cal.getTime())+";";
//指定月份最后一天
int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, lastDay);
firstAndLastDay += sdf.format(cal.getTime());
return firstAndLastDay;
}