Java Month Get getStrOfNextMonth(String dateStr)

Here you can find the source of getStrOfNextMonth(String dateStr)

Description

get Str Of Next Month

License

Open Source License

Declaration

public static String getStrOfNextMonth(String dateStr) 

Method Source Code

//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);
        }
    }
}

Related

  1. getReportMonthString()
  2. getSelectMonth(String month)
  3. getShortMonthForInt(final Locale locale, int theMonth)
  4. getSpecficMonthStart(Date date, int amount)
  5. getStartDateOfMonth(String yyyymm)
  6. getStrThisMonth()
  7. getThisMonth()
  8. getThisMonth()
  9. getThisMonth()