计算n个月之后的今天

public static String getEtime(String dtime,int n) throws Exception{//计算n个月之后的今天
  String ctime="";
  SimpleDateFormat sdfFormat=new SimpleDateFormat("yyyy-MM-dd");
  if(Integer.parseInt(dtime.substring(8, 10))==31||Integer.parseInt(dtime.substring(8, 10))==30||Integer.parseInt(dtime.substring(8, 10))==29){//取款日期是31或30号
   String time1=dtime.subSequence(5, 7).toString();//
   int montha=Integer.parseInt(time1)+n;
   if(montha==2){//如果是2月(2月最后一天还)
    String  time2=dtime.substring(0, 5)+"02-01";
    ctime=sdfFormat.format(lastDayOfMonth(sdfFormat.parse(time2)));
   }else if(Integer.parseInt(dtime.substring(8, 10))==31){//最后一天
    String  time2=dtime.substring(0, 5)+(montha>10?montha+"":"0"+montha)+"-01";
    ctime=sdfFormat.format(lastDayOfMonth(sdfFormat.parse(time2)));
   }else {//剩下的是30
    ctime=Nextmonth.getnextmonthtime(dtime, n);//n个月后未提前的应还日
   }
  }else{//取款日期是其他日期
   ctime=Nextmonth.getnextmonthtime(dtime, n);//n个月后未提前的应还日
  }
  return ctime;
 }

你可能感兴趣的:(计算n个月之后的今天)