One of the most recent projects has a foreground for the table header requirements:
Returns the shape of a given date period as
Mar 2015 3/20-3/31
APR 2015 4/1-4/30
This month year data, simply write down the code, temporarily did not think of a better way
For example, the passed in parameter is "2015-03-20"-"2016-04-08" such form
Three-stage processing:
First paragraph: The end of the start date of the start date
Second paragraph: Data for all months between the start and end months
Third paragraph: End date of the beginning of the month to the end date
1 PublicList<string> loadmonthstr (String startdate, String endDate)throwsException {2List<string> periodlist =NewArraylist<>();3SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd");4GregorianCalendar Cdstart =NewGregorianCalendar ();5GregorianCalendar Cdend =NewGregorianCalendar ();6 Cdstart.settime (Sdf.parse (StartDate));7 Cdend.settime (Sdf.parse (endDate));8 9SDF =NewSimpleDateFormat ("MMM yyyy", locale.us);Ten intFirststart =Cdstart.get (calendar.day_of_month); One A intLastend =Cdend.get (calendar.day_of_month); - intMonthofyear = Cdstart.get (calendar.month) + 1; - the BooleanSameyearmonth =false; - String datestr; - if(Cdstart.get (calendar.month) = = Cdend.get (calendar.month) && cdstart.get (calendar.year) = =Cdend.get (calendar.year)) { -Sameyearmonth =true; + } - + if(sameyearmonth) { ADatestr = Sdf.format (Cdstart.gettime ()) + "" + Monthofyear + "/" + Firststart + "-" + Monthofyear + "/" +Lastend; at Periodlist.add (DATESTR); -}Else { -Datestr = Sdf.format (Cdstart.gettime ()) + "" + Monthofyear + "/" + cdstart.get (calendar.day_of_month) + "-" -+ Monthofyear + "/" +Cdstart.getmaximum (calendar.day_of_month); - Periodlist.add (DATESTR); -Cdstart.set (Calendar.day_of_month, 1); inCdend.set (Calendar.day_of_month, 1); -Cdstart.add (Calendar.month, 1); to intStartDay = 0; + intEndday = 0; - while(Cdstart.compareto (Cdend) < 0) { theMonthofyear = Cdstart.get (calendar.month) + 1; *StartDay = 1; $Endday =Cdstart.getactualmaximum (calendar.day_of_month);Panax NotoginsengDatestr = Sdf.format (Cdstart.gettime ()) + "" + Monthofyear + "/" + StartDay + "-" + Monthofyear + "/" +Endday; -Cdstart.add (Calendar.month, 1); the Periodlist.add (DATESTR); + } ADatestr = Sdf.format (Cdend.gettime ()) + "" + (Cdend.get (calendar.month) + 1) + "/" + 1 + "-" the+ (Cdend.get (calendar.month) + 1) + "/" +Lastend; + Periodlist.add (DATESTR); - } $ returnperiodlist; $}
Java returns data of the form 2015 3/20-3/31 for a given date