/**
* 獲取當前時間所在周的周一和周日的日期時間
* @return
*/
public static Map<String,String> getWeekDate() {
Map<String,String> map = new HashMap();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
// 設置一個星期的第一天,按中國的習慣一個星期的第一天是星期一
cal.setFirstDayOfWeek(Calendar.MONDAY);
// 獲得當前日期是一個星期的第幾天
int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
if(dayWeek==1){
dayWeek = 8;
}
cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - dayWeek);// 根據日歷的規則,給當前日期減去星期幾與一個星期第一天的差值
Date mondayDate = cal.getTime();
String weekBegin = sdf.format(mondayDate);
cal.add(Calendar.DATE, 4 +cal.getFirstDayOfWeek());
Date sundayDate = cal.getTime();
String weekEnd = sdf.format(sundayDate);
map.put("mondayDate", weekBegin);
map.put("sundayDate", weekEnd);
return map;
}