取得指定月份的第一天与取得指定月份的最后一天
/**
* 取得指定月份的第一天
*
* @param strdate String
* @return String
*/
public String getMonthBegin(String strdate)
{
java.util.Date date = parseFormatDate(strdate);
return formatDateByFormat(date,"yyyy-MM") + "-01";
}
/**
* 取得指定月份的最后一天
*
* @param strdate String
* @return String
*/
public String getMonthEnd(String strdate)
{
java.util.Date date = parseFormatDate(getMonthBegin(strdate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH,1);
calendar.add(Calendar.DAY_OF_YEAR, -1);
return formatDate(calendar.getTime());
}
/**
* 常用的格式化日期
*
* @param date Date
* @return String
*/
public String formatDate(java.util.Date date)
{
return formatDateByFormat(date,"yyyy-MM-dd");
}
/**
* 以指定的格式来格式化日期
*
* @param date Date
* @param format String
* @return String
*/
public String formatDateByFormat(java.util.Date date,String format)
{
String result = "";
if(date != null)
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat(format);
result = sdf.format(date);
}
catch(Exception ex)
{
LOGGER.info("date:" + date);
ex.printStackTrace();
}
}
return result;
}