Java Date to Month getMonth(Date d)

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

Description

Jan = 1 ...

License

Open Source License

Declaration

public static int getMonth(Date d) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    /**//from   ww  w  . j  av a  2s .c  om
     * Jan = 1 ... Dec = 12
     */
    public static int getMonth(Date d) {
        Calendar c = getCalendar();
        c.setTime(d);
        return (c.get(Calendar.MONTH) + 1);
    }

    /**
     * month ranges from 1 to 12 (not 0 to 11)
     */
    private static Calendar getCalendar() {
        return (getCalendar(null, null));
    }

    private static Calendar getCalendar(TimeZone timeZone, Locale locale) {
        if (timeZone == null)
            timeZone = TimeZone.getDefault();

        if (locale == null)
            locale = Locale.getDefault();

        Calendar c = new GregorianCalendar(timeZone, locale);
        return (c);
    }

    public static Date setTime(Date d, long time) {
        d.setTime(time);
        return (d);
    }
}

Related

  1. getMonday(Date date)
  2. getMondayDate(String date)
  3. getMontByDate(Date curDate)
  4. getMonth(Date aDate)
  5. getMonth(Date d)
  6. getMonth(Date d)
  7. getMonth(Date d)
  8. getMonth(Date date)
  9. getMonth(Date date)