Java Month of Year getNextMonth()

Here you can find the source of getNextMonth()

Description

get Next Month

License

Open Source License

Declaration

public static Date getNextMonth() 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getNextMonth() {
        String pattern = "yyyy-MM-dd";
        Calendar cd = Calendar.getInstance();
        cd.add(Calendar.MONTH, 1);
        String newTime = String.valueOf(cd.get(Calendar.YEAR)) + "-" + String.valueOf(cd.get(Calendar.MONTH) + 1)
                + "-" + String.valueOf(cd.get(Calendar.DAY_OF_MONTH));
        return convertStringToDate(newTime, pattern);
    }//from w  w w  .ja v  a 2s.c  o m

    public static Date convertStringToDate(String dateStr, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            return format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. getMonthOfYear(int m)
  2. getMonthOfYear(long time)
  3. getMonthOfYearFromTimestamp(long ms)
  4. getMonthStart(int year, int month)
  5. getNextiMonth(Date date, int month)
  6. getNextMonth(Calendar aCal)
  7. getNextMonth(Date nowdate, int delay)
  8. getNextMonthFirstDay(String date)
  9. getNextMonthFirstDay(T day)