Android Month Date Get getCurrentMonth()

Here you can find the source of getCurrentMonth()

Description

Gets the month element from today date.

Return

int -the date/day from today.

Declaration

public static int getCurrentMonth() 

Method Source Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main{
    /** /*from www.jav  a 2 s  .com*/
     * Gets the month element from today date.
     * <br>
     * Internally calls {@link #getMonthFromDate(Date)}
     * <br>
     *  E.g.,
     *  <pre>
     *      getCurrentMonth() = 10
     *      //where today date is Oct 09 12:04:47
     *  </pre> 
     *   
     * @return int -the date/day from today.
     * 
     */
    public static int getCurrentMonth() {
        return getMonthFromDate(new Date());
    }
    /** 
     * Gets the month element from given {@link Date} object.
     * 
     * @param date -{@link Date} object.
     * @return int -the month from given date.
     * @throws NullPointerException if any of the parameters is null.
     */
    public static int getMonthFromDate(Date date) {
        if (StringUtils.isNull(date)) {
            throw new NullPointerException("date cannot be null");
        }
        Calendar calendar = Calendar.getInstance();
        if (date != null) {
            calendar.setTime(date);
        }
        return calendar.get(Calendar.MONTH) + 1;
    }
}

Related

  1. getCurrentMonth(Date date)
  2. monthNumber(Date date)
  3. maxMonthDate(Date date)
  4. getMonthStartDate(Date date)
  5. getMonthEndDate(Date date)
  6. monthNumber()
  7. getInterval(String beginMonth, String endMonth)
  8. monthOffset(Date date, int offset)
  9. getMonth()