Java Month Convert nextMonth()

Here you can find the source of nextMonth()

Description

next Month

License

Apache License

Declaration

public static final int nextMonth() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static final int nextMonth() {
        String next = format(new Date(), "M");
        int nextMonth = Integer.parseInt(next) + 1;
        if (nextMonth == 13)
            return 1;
        return nextMonth;
    }/*  w  ww.ja  v a  2  s . c o  m*/

    /**
      * @param date
      * @param pattern: Date format pattern
      * @return
      */
    public static final <T extends Date> String format(T date, String pattern) {
        if (date == null)
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            String result = df.format(date);
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. monthIndexAsString(Integer index, Integer offset)
  2. monthNumber(String s)
  3. monthOfDate(Date s)
  4. monthsBetween(String from, String to)
  5. monthStringToInt(String month)
  6. nextMonth(Date date)
  7. nextMonth(Date date)
  8. parseMonth(final String source)
  9. setMonths(Date date, int amount)