throws ParseException {
SimpleDateFormat df = null;
Date date = null;
df = new SimpleDateFormat("yyyy-MM-dd");
try {
date = df.parse(strDate);
} catch (ParseException pe) {
log.error("ParseException: " + pe);
}
return (date);
}
public static Calendar getCalendar(String month, int week) {
Date newDate = DateUtil.convertStringToDate(month + "-01");
Calendar caleNew = Calendar.getInstance();
caleNew.setTime(newDate);
caleNew.add(Calendar.WEEK_OF_MONTH, week -1 );
return caleNew;
}
/**
* 获取某月的第n星期的第一天
*
* @param month: 2011-06
* @param week : 2
* @return
*/
public static Date getFirstOfWeek(String month, int week) {
Calendar myCale = Calendar.getInstance();
try{
GregorianCalendar gc = (GregorianCalendar)getCalendar(month, week ) ; //(GregorianCalendar)Calendar.getInstance();
myCale.setTime(gc.getTime());
myCale.set(Calendar.DATE, gc.get(Calendar.DATE) - gc.get(Calendar.DAY_OF_WEEK) + 2);
}catch (Exception e) {
log.info(e.getMessage());
}
return myCale.getTime();
}
/**
* 获取某月的第n星期的最后一天
*
* @param month: 2011-06
* @param week: 2
* @return
*/
public static Date getLastOfWeek(String month, int week) {
Calendar myCale = Calendar.getInstance();
try{
GregorianCalendar gc = (GregorianCalendar)getCalendar(month, week ) ; //(GregorianCalendar)Calendar.getInstance();
myCale.setTime(gc.getTime());
myCale.set(Calendar.DATE, gc.get(Calendar.DATE) + 8 - gc.get(Calendar.DAY_OF_WEEK) );
}catch (Exception e) {
log.info(e.getMessage());
}
return myCale.getTime();
}
转载于:https://my.oschina.net/weiqinxue/blog/725321