/** * Gets the first and last day of the week of the specified date, with an underscore connection * @param datastr * @return * @throws parseexception*/ Public Staticstring Getfirstandlastofmonth (String datastr,string dateformat,string Resultdateformat) throws ParseException { //get the first day of the current month:Calendar C =calendar.getinstance (); C.settime (NewSimpleDateFormat (DateFormat). Parse (DATASTR)); C.add (Calendar.month,0); C.Set(Calendar.day_of_month,1);//set to number 1th, the current date is the first day of the monthString first =NewSimpleDateFormat (Resultdateformat). Format (C.gettime ()); System. out. println ("===============first:"+First ); //get the last day of the current monthCalendar CA =calendar.getinstance (); ca.Set(Calendar.day_of_month, Ca.getactualmaximum (Calendar.day_of_month)); String Last=NewSimpleDateFormat (Resultdateformat). Format (Ca.gettime ()); System. out. println ("===============last:"+Last ); returnfirst+"_"+Last ; } /** * First and last day of the week * @param datastr * @param dateformat * @param resultdateformat * @return * @th Rows ParseException*/ Public Staticstring Getfirstandlastofweek (String datastr,string dateformat,string Resultdateformat) throws ParseException { Calendar Cal=calendar.getinstance (); Cal.settime (NewSimpleDateFormat (DateFormat). Parse (DATASTR)); intD =0; if(Cal.Get(calendar.day_of_week) = =1) {D= -6; } Else{d=2-Cal.Get(Calendar.day_of_week); } cal.add (Calendar.day_of_week, D); //Week Start dateString data1 =NewSimpleDateFormat (Resultdateformat). Format (Cal.gettime ()); Cal.add (Calendar.day_of_week,6); //Week End DateString data2 =NewSimpleDateFormat (Resultdateformat). Format (Cal.gettime ()); returnData1 +"_"+data2; }
Java gets the first day and last day of the month, gets the first and last day of the week
Use the scene, calculate the day active, week active, month active is the date calculation
Java gets the first day and last day of the month, gets the first and last day of the week