Java Date to Month getMonthOfYear(Date date)

Here you can find the source of getMonthOfYear(Date date)

Description

get Month Of Year

License

LGPL

Declaration

public static int getMonthOfYear(Date date) 

Method Source Code

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

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

public class Main {
    public static int getMonthOfYear(Date date) {
        return getField(date, Calendar.MONTH);
    }/*from  ww  w .j  a  v  a2 s .  c  o  m*/

    public static int getField(Date date, int field) {
        int result = -1;
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            result = calendar.get(field);
        }
        return result;
    }
}

Related

  1. getMonthlyKey(Date d)
  2. getMonthName(Date date)
  3. getMonthOfCurrentTime(Date date)
  4. getMonthOffset(Date sourceDate, Date targetDate)
  5. getMonthOfThisYear(Date currentdate)
  6. getMonthOfYear(Date dt)
  7. getMonthOfYear(final Date date)
  8. getMonthRate(Date date, boolean moveIn)
  9. getMonths(Date date1, Date date2)