Here you can find the source of getMonthAdd(String operateDate, int flag)
public static String getMonthAdd(String operateDate, int flag) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static String getMonthAdd(String operateDate, int flag) throws ParseException { if (operateDate.length() == 7) { operateDate = operateDate + "-01"; }/*www .j a v a 2s . c om*/ DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c1 = Calendar.getInstance(); c1.setTime(sdf.parse(operateDate)); c1.add(Calendar.MONTH, flag); return sdf.format(c1.getTime()).substring(0, 7); } }