The following example code introduces you to the java date format plus the specified number of months to get a new date. The specific code is as follows:
public static Date getnewDate(Date olddate, String recordDate) throws ParseException { Date date = olddate; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String data = format.format(date); String dataStr[] = data.split("-"); //Year int year = (Integer.parseInt(dataStr[1]) + Integer.parseInt(recordDate))/12; //Moon int yue = (Integer.parseInt(dataStr[1]) + Integer.parseInt(recordDate))%12; String a = ""; if(yue<10){ if(yue<1){ a = "12"; }else{ a = "0"+yue; } }else { a = yue+""; } dataStr[0]=String.valueOf(Integer.parseInt(dataStr[0]) + year); dataStr[1]=a; String newdata = dataStr[0]+"-"+dataStr[1]+"-"+dataStr[2]; Date newDate = format.parse(newdata); return newDate;}Below is a Java implementation code that adds a specified date plus a specified number of days to get a new date.
package com.date.test; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Test {public static void main(String[] args) throws ParseException {SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // Date format Date date = dateFormat.parse("2015-07-31"); // Specify date Date newDate = addDate(date, 20); // Specify date plus 20 days System.out.println(dateFormat.format(date));// Output the formatted date System.out.println(dateFormat.format(newDate));}public static Date addDate(Date date,long day) throws ParseException { long time = date.getTime(); // Get the milliseconds of the specified date day = day*24*60*60*1000; // Convert the days to be added to milliseconds time+=day; // Add to get a new milliseconds return new Date(time); // Convert the milliseconds to date} }