Java Date to Month month(final Date date)

Here you can find the source of month(final Date date)

Description

Returns the month from the day, i.e.

License

Apache License

Declaration

public static int month(final Date date) 

Method Source Code


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

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static java.util.Calendar.*;

public class Main {
    /**/*from  w  w w  .  j  a  v  a  2  s  .  c om*/
     * Returns the month from the day, i.e. a number between 1 (January) and 12 (December).
     */
    public static int month(final Date date) {
        return fromDateToCalendar(date).get(MONTH) + 1;
    }

    public static Calendar fromDateToCalendar(final Date date) {
        final Calendar cal = new GregorianCalendar();
        cal.clear();
        cal.setMinimalDaysInFirstWeek(4);
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.setTime(date);

        return cal;
    }
}

Related

  1. getNextMonthFirstDay(Date date)
  2. getNextMonthPreviousDay(Date date, int month_num)
  3. getNextMonthsByStartDate(Date date, int month)
  4. month(Date date)
  5. month(Date inDate, TimeZone timeZone)
  6. monthBegin(final Date date)
  7. monthOf(Date date)