上周一及上周天日期
public static Map<String, String> getMonToSunday() {
Calendar preWeekSundayC = Calendar.getInstance();
Calendar preWeekMondayCal = Calendar.getInstance();
//上周天时间
preWeekSundayC.set(Calendar.DAY_OF_WEEK, 1);
//设置时间成本周第一天(周日)
preWeekMondayCal.set(Calendar.DAY_OF_WEEK, 1);
//上周一时间
preWeekMondayCal.add(Calendar.DATE, -6);
//转化为日期
Date preWeekMonday = preWeekMondayCal.getTime();
Map<String, String> result = new HashMap<>();
result.put("mon", DateUtil.format(preWeekMonday, "yyyy-MM-dd") + " 00:00:00");
result.put("sun", DateUtil.format(preWeekSundayC.getTime(), "yyyy-MM-dd") + " 00:00:00");
return result;
}
本周一及本周天时间
public static String getSunday() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(Locale.CHINA);
c.setFirstDayOfWeek(Calendar.MONDAY);
//当前时间,貌似多余,其实是为了所有可能的系统一致
c.setTimeInMillis(System.currentTimeMillis());
// System.out.println("当前时间:" + format.format(c.getTime()));
// c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// System.out.println("周一时间:" + format.format(c.getTime()));
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
// System.out.println("本周天时间:" + format.format(c.getTime()));
return format.format(c.getTime());
}