可能是这样的:
for(int i=0;i<15;i++){ Calendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_MONTH, -1); if (cal.Calendar.DAY_OF_WEEK==1){ System.out.println(cal.cal.getTime())
但是可能存在更简单的方法吗?谢谢。
您走在正确的轨道上。
Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -7); // First week before cal.add(Calendar.DAY_OF_YEAR, -7); // Second week before
让我仅在星期一进行这项工作。
Calendar cal = Calendar.getInstance(); int weekday = cal.get(Calendar.DAY_OF_WEEK); int days = (Calendar.SATURDAY - weekday + 2) % 7; cal.add(Calendar.DAY_OF_YEAR, days); cal.add(Calendar.DAY_OF_MONTH, -7); cal.add(Calendar.DAY_OF_MONTH, -7);