获取本周一的日期和本周日的日期

public Map getWeekDate (){

  Map map = new HashMap();

  Date date = new Date();

  Calendar cal = Calendar.getInstance();

  int dayWeek = cal.get(Calendar.DAY_OF_WEEK)-1;

  if(dayWeek==0){

    dayWeek = 7;

  }

 

  calendar.add(Calendar.DATE , cal.getFirstDayOfWeek()-dayWeek);

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

  String mondayDate = sdf.format(cal.gettime());

  map.put("mondayDate",mondayDate);

  calendar.add(Calendar.DATE , 6);

  String sundayDate = sdf.format(cal.gettime());

  map.put("sundayDate",sundayDate);

}

posted @ 2020-07-02 15:56  790021521  阅读(711)  评论(0编辑  收藏  举报