Java Date to Month getMonth(Date date)

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

Description

Returns a int value indicating the number of the month.

License

Open Source License

Parameter

Parameter Description
date the <code>Date</code> to be parsed.

Return

a int value of the number of the month.

Declaration

public static int getMonth(Date date) 

Method Source Code


//package com.java2s;
/*/*from   www.j  ava2  s  . c o m*/
 * Copyright (c) Red de Pruebas C.A. All rights reserved.
 * RED DE PRUEBAS C.A. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

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

public class Main {
    /**
     * Returns a <code>int</code> value indicating the number of the month.
     * <p>
     * Parses a given <code>Date</code> to <code>Calendar</code> using
     * {@link #parseDateToCalendar} method and returns the value of the number
     * of the month.
     *
     * @param date the <code>Date</code> to be parsed.
     * @return a <code>int</code> value of the number of the month.
     * @see #parseDateToCalendar(java.util.Date)
     * @see java.util.Calendar#get(int)
     * @see java.util.Calendar#MONTH
     * @since 0.1
     */
    public static int getMonth(Date date) {
        return parseDateToCalendar(date).get(Calendar.MONTH);
    }

    /**
     * Returns a <code>Calendar</code> object setting Calendar's time with the
     * given <code>Date</code> object.
     * <p>
     * From a <code>Calendar</code> object based on the current time in the
     * default time zone with the default locale sets this Calendar's time with
     * the given <code>Date</code>.
     *
     * @param date the given Date.
     * @return a <code>Calendar</code> object setting Calendar's time with the
     * given <code>Date</code>
     * @see java.util.Calendar#getInstance()
     * @see java.util.Calendar#setTime(java.util.Date)
     * @since 0.1
     */
    public static Calendar parseDateToCalendar(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }
}

Related

  1. getMonth(Date date)
  2. getMonth(Date date)
  3. getMonth(Date date)
  4. getMonth(Date date)
  5. getMonth(Date date)
  6. getMonth(Date date)
  7. getMonth(Date dateParam)
  8. getMonth(Date... objects)
  9. getMonth(java.util.Date date)