Java Date Now getCurrentMonth()

Here you can find the source of getCurrentMonth()

Description

get Current Month

License

Apache License

Declaration

public static Integer getCurrentMonth() 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Integer getCurrentMonth() {
        return getMonth(new Date());
    }//from  w  ww. ja  v  a2 s  . c o  m

    public static Integer getMonth(Date date) {
        if (date == null)
            return null;
        String month = format(date, "M");
        return Integer.parseInt(month);
    }

    /**
      * @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. getCurrentJnlpTimestamp()
  2. getCurrentLastDate()
  3. getCurrentLocaleTime()
  4. getCurrentMinutes()
  5. getCurrentMonth()
  6. getCurrentMonth()
  7. getCurrentMonth(boolean bool, String currentDate)
  8. getCurrentMonthday()
  9. getCurrentMonthLastDay()