Java Date to Month getMonth(Date date)

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

Description

get Month

License

Open Source License

Declaration

public static int getMonth(Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static int getMonth(Date date) {
        Calendar calendar = getCalendarFromDate(date);
        return calendar.get(Calendar.MONTH) + 1;
    }/*from www.ja  v  a  2  s  .com*/

    /**
     * get calendar from date
     *
     * @param date the passing date
     * @return the calendar instance
     */
    public static Calendar getCalendarFromDate(Date date) {
        Calendar calendar = getDefaultCalendar();
        calendar.setTime(date);
        return calendar;
    }

    /**
     * get the default calendar
     *
     * @return the calendar instance
     */
    public static Calendar getDefaultCalendar() {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        return calendar;
    }
}

Related

  1. getMonth(Date d)
  2. getMonth(Date d)
  3. getMonth(Date d)
  4. getMonth(Date date)
  5. getMonth(Date date)
  6. getMonth(Date date)
  7. getMonth(Date date)
  8. getMonth(Date date)
  9. getMonth(Date date)