Java Day in Month getDayOfMonth(Date date)

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

Description

get Day Of Month

License

Open Source License

Declaration

public final static long getDayOfMonth(Date date) throws ParseException 

Method Source Code


//package com.java2s;

import java.text.ParseException;

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

public class Main {

    public final static long getDayOfMonth(Date date) throws ParseException {
        int year = getYearOfDate(date);
        int month = getMonthOfDate(date) - 1;
        int day = getDayOfDate(date);
        int hour = getHourOfDate(date);
        int minute = getMinuteOfDate(date);
        int second = getSecondOfDate(date);
        Calendar l_calendar = new GregorianCalendar(year, month, day, hour, minute, second);
        return l_calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }//from  w  ww .j a v a 2s .com

    public final static int getYearOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.YEAR);
    }

    public final static int getMonthOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.MONTH) + 1;
    }

    public final static int getDayOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.DAY_OF_MONTH);
    }

    public final static int getHourOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.HOUR_OF_DAY);
    }

    public final static int getMinuteOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.MINUTE);
    }

    public final static int getSecondOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.SECOND);
    }

    /**
     * get field value by date and the field, like get the year of a date
     *
     * @param date
     * @param field
     * @return
     */
    public final static int getFieldValueByDate(Date date, int field) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(field);
    }
}

Related

  1. getCountDayForMonth(int year, int month)
  2. GetDay(int month)
  3. getDayByOfSomeMonth(String curday, int month)
  4. getDayMonth(String dayofmonth)
  5. getDayOfMonth(Date d)
  6. getDayOfMonth(Date p_date)
  7. getDayOfMonth(int dayOfYear, boolean leap)
  8. getDayOfMonth(int month, int year)
  9. getDayOfMonth(long time)