Public static void main (String[] args) throws ParseException { Simpledateformat sdf=new simpledateformat ("Yyyy-mm-dd"); //set time format calendar cal = calendar.getinstance (); date time=sdf.parse ("2015-9-4 14:22:47"); cal.settime (Time); system.out.println ("To calculate Date:" +sdf.format (Cal.gettime ())) //output to calculate date // Determine whether the date to be calculated is Sunday, if it is minus one day to calculate the Saturday, otherwise there will be a problem, calculated to the next week Int dayweek = cal.gET (Calendar.day_of_week);//Get the current date is the first day of the one weeks if (1 == dayweek) { cal.add (calendar.day_of_month, -1); } cal.setfirstdayofweek (calendar.monday);//Set one the first day of the week, according to the Chinese habit one weeks the first day is Monday int day = Cal.get (Calendar.day_of_week);//Get the current date is the day of the one week Cal.add (Calendar.date, cal.getfirstdayofweek ()-day);//According to the rules of the calendar, subtract the difference between the day of the week and the first of the one weeks of the current date system.out.println ("Date of week Monday:" +sdf.format (Cal.getTime ())); &Nbsp; system.out.println (Cal.getfirstdayofweek () + "-" +day+ "+6=" + (Cal.getfirstdayofweek ()-day+6)); cal.add ( CALENDAR.DATE, 6); system.out.println ("Date of week Sunday:" + Sdf.format (Cal.gettime ())); }
Java calculates the Monday and Sunday of the week based on the specified date