获取指定年月的第一天
/**
* 获取指定年月的第一天
* @param year
* @param month
* @return
* @throws ParseException
*/
@SuppressWarnings("unused")
private String getFirstDayOfMonth1(String date) throws ParseException {
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date curDate = new Date();
if(StringUtils.isNotBlank(date)){
curDate = sdf.parse(date);
}
Calendar cal = Calendar.getInstance();
cal.setTime(curDate);
//获取某月最小天数
int firstDay = cal.getMinimum(Calendar.DATE);
//设置日历中月份的最小天数
cal.set(Calendar.DAY_OF_MONTH,firstDay);
return df.format(cal.getTime());
}
获取指定年月的最后一天
/**
* 获取指定年月的最后一天
* @param year
* @param month
* @return
* @throws ParseException
*/
@SuppressWarnings("unused")
private String getLastDayOfMonth1(String date) throws ParseException {
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date curDate = new Date();
if(StringUtils.isNotBlank(date)){
curDate = sdf.parse(date);
}
cal.setTime(curDate);
//获取某月最大天数
int lastDay = cal.getActualMaximum(Calendar.DATE);
//设置日历中月份的最大天数
cal.set(Calendar.DAY_OF_MONTH, lastDay);
return df.format(cal.getTime());
}