JAVA日期调整,往前几天,往后几天

public String getDate(String predate, int days){
		String afterDate = predate;
		try{
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			Date date = dateFormat.parse(predate);
			
			GregorianCalendar gc =new GregorianCalendar();
			gc.setTime(date);
			gc.add(GregorianCalendar.DATE, days);
			
			date = gc.getTime();
			afterDate = dateFormat.format(date);
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		return afterDate;
	}

你可能感兴趣的:(JAVA日期调整,往前几天,往后几天)