1、public static String getEnd(){Calendar c=Calendar.getInstance(); c.add(Calendar.MONTH, -1); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
2、c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59); //按格式输出 String gtime = sdf.format(c.getTime()); //上月最后一天 return gtime; }
3、public static String getStart(){Calendar c=Calendar.getInstance(); c.add(Calendar.MONTH, -1); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-01 00:00:00"); String gtime2 = sdf2.format(c.getTime()); //上月第一天 return gtime2; }