Ideas:
Get the start and end date of the current quarter first, pushing forward 3 months on the current date, i.e. the start and end dates of the previous quarter
/** * @param flag true: Start date, false: End date * @return */public static String Getlastquartertime (Boolean flag) {SimpleDateFormat SHORTSDF = new SimpleDateFormat ("Yyyy-mm-dd"); SimpleDateFormat longsdf = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String resultdate= "";D ate now = null;try {Calendar calendar = calendar.getinstance (); int currentmonth = Calendar.get (Cale Ndar. MONTH) + 1;//true: Start date, false: End date if (flag) {if (currentmonth >= 1 && currentmonth <= 3) Calendar.set ( Calendar.month, 0), else if (currentmonth >= 4 && currentmonth <= 6) Calendar.set (Calendar.month, 3); else if ( Currentmonth >= 7 && currentmonth <= 9) Calendar.set (Calendar.month, 6); else if (Currentmonth >= ten && Amp Currentmonth <=) Calendar.set (Calendar.month, 9); Calendar.set (calendar.date, 1); now = Longsdf.parse ( Shortsdf.format (Calendar.gettime ()) + "00:00:00"); Else{if (currentmonth >= 1 && currentmonth <= 3) {Calendar.set (Calendar.month, 2); Calendar.set (Calendar. DATE, 31); } else if (Currentmonth >= 4 && currentmonth <= 6) {Calendar.set (Calendar.month, 5); Calendar.set (Calendar.date, 30); } else if (currentmonth >= 7 && currentmonth <= 9) {Calendar.set (calendar.month, 8); Calendar.set (Calendar.date, 30); } else if (currentmonth >= && currentmonth <=) {calendar.set (calendar.month, 11); Calendar.set (Calendar.date, 31); }now = Longsdf.parse (Shortsdf.format (Calendar.gettime ()) + "23:59:59");} Calendar.settime (now);//Set Date Calendar.add (Calendar.month,-3); resultdate = Longsdf.format (Calendar.gettime ());} catch (Exception e) {;} return resultdate;}
Use the Java Calendar object to get the start and end times of the current date