本月最后一天,下个月倒数第二天

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//
  Calendar calendar = new GregorianCalendar();

  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.DATE, 1);
  cal.roll(Calendar.DATE, -1);
  Date endTime = cal.getTime();
  String aa = df.format(endTime);// 本月最后一天
  System.out.println(aa);

    int month = cal.get(Calendar.MONTH) + 1;
     int year = cal.get(Calendar.YEAR);

  cal.set(Calendar.YEAR,year);
  cal.set(Calendar.MONTH, month+ 1);
  cal.set(Calendar.DAY_OF_MONTH, 1);
  cal.add(Calendar.DAY_OF_MONTH, -2);
  String bb = df.format(cal.getTime());//下个月倒数第二天
  System.out.println("daoshu"+bb);

你可能感兴趣的:(本月最后一天,下个月倒数第二天)