获取本周第一天和最后一天,按周一至周日计算

/**
* 获取本周的第一天
* @return String
* **/
public static String getWeekStart(){
Calendar cal=Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setTime(new java.util.Date());
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); // Monday
java.util.Date time=cal.getTime();
return new SimpleDateFormat("yyyy-MM-dd").format(time)+" 00:00:00";
}

/**
* 获取本周的最后一天
* @return String
* **/
public static String getWeekEnd(){
Calendar cal=Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setTime(new java.util.Date());
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + 6); // Sunday
java.util.Date time=cal.getTime();
return new SimpleDateFormat("yyyy-MM-dd").format(time)+" 23:59:59";
}
posted @ 2020-09-06 09:43  六元  阅读(1417)  评论(0编辑  收藏  举报