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

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);

}

上一篇:python—模块和包


下一篇:python之彻底搞懂迭代、可迭代、迭代器的区别(五)