// 获取本周周一,周末的日期 public static void main(String[] args) throws ParseException { String nt = "2021-1-1"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar firstDayOfWeek = Calendar.getInstance(Locale.getDefault()); firstDayOfWeek.setFirstDayOfWeek(Calendar.MONDAY); int day = firstDayOfWeek.get(Calendar.DAY_OF_WEEK); firstDayOfWeek.add(Calendar.DATE, -day+1+1);// 后面的+1是因为从周日开始 Date firstDayOfWeek1 = firstDayOfWeek.getTime(); // 周一 Calendar lastDayOfWeek = Calendar.getInstance(Locale.getDefault()); lastDayOfWeek.setFirstDayOfWeek(Calendar.MONDAY); day = lastDayOfWeek.get(Calendar.DAY_OF_WEEK); lastDayOfWeek.add(Calendar.DATE, 7-day+1); // 本周星期天的日期 Date lastDayOfWeek1 = lastDayOfWeek.getTime(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)