Here you can find the source of getStrOfNextMonth(String dateStr)
public static String getStrOfNextMonth(String dateStr)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getStrOfNextMonth(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {/*from ww w .j a v a2 s . co m*/ Date date = sdf.parse(dateStr); Calendar c = Calendar.getInstance(); c.setTime(date); return sdf.format(getDateOfNextMonth(c).getTime()); } catch (ParseException e) { throw new IllegalArgumentException( "Invalid date format(yyyy-MM-dd): " + dateStr); } } public static Calendar getDateOfNextMonth(Calendar date) { Calendar lastDate = (Calendar) date.clone(); lastDate.add(Calendar.MONTH, 1); return lastDate; } public static Calendar getDateOfNextMonth(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { Date date = sdf.parse(dateStr); Calendar c = Calendar.getInstance(); c.setTime(date); return getDateOfNextMonth(c); } catch (ParseException e) { throw new IllegalArgumentException( "Invalid date format(yyyy-MM-dd): " + dateStr); } } }