java获取某个时间的上周一和周日



Calendar cal = Calendar.getInstance();


//n为推迟的周数,1本周,-1向前推迟一周,2下周,依次类推


int n = 1;


String monday;


cal.add(Calendar.DATE, n*7);


//想周几,这里就传几Calendar.MONDAY(TUESDAY...)


cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);


monday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());


System.out.println(monday);

你可能感兴趣的:(java获取某个时间的上周一和周日)