Java Utililty Methods Day in Month

List of utility methods to do Day in Month

Description

The list of methods to do Day in Month are organized into topic(s).

Method

StringfirstDayOfNextMonth(String dateFormat)
get first day of next month in specified date format.
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, 1);
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
return formatter.format(cal.getTime());
intgetCountDayForMonth(int year, int month)
get Count Day For Month
if (month > 12)
    return 0;
int[] monDays = new int[] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (((year) % 4 == 0 && (year) % 100 != 0) || (year) % 400 == 0)
    monDays[2]++;
return monDays[month];
StringGetDay(int month)
Get Day
java.util.Calendar cal = java.util.Calendar.getInstance();
java.text.SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.MONTH, month);
sDateFormat.format(cal.getTime());
System.out.println(sDateFormat.format(cal.getTime()));
return sDateFormat.format(cal.getTime());
StringgetDayByOfSomeMonth(String curday, int month)
get Day By Of Some Month
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
Date mydate = formatter.parse(curday);
Calendar calendar = Calendar.getInstance();
calendar.setTime(mydate);
calendar.add(Calendar.MONTH, month);
return formatter.format(calendar.getTime());
StringgetDayMonth(String dayofmonth)
get Day Month
return dayofmonth;
intgetDayOfMonth(Date d)
Get the day of the month from a Date object.
return Integer.parseInt(new SimpleDateFormat("dd").format(d));
longgetDayOfMonth(Date date)
get Day Of Month
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);
...
longgetDayOfMonth(Date p_date)
get Day Of Month
int year = getYearOfDate(p_date);
int month = getMonthOfDate(p_date) - 1;
int day = getDayOfDate(p_date);
int hour = getHourOfDate(p_date);
int minute = getMinuteOfDate(p_date);
int second = getSecondOfDate(p_date);
Calendar l_calendar = new GregorianCalendar(year, month, day, hour, minute, second);
return l_calendar.getActualMaximum(l_calendar.DAY_OF_MONTH);
...
intgetDayOfMonth(int dayOfYear, boolean leap)
Converts the number of elapsed days from beginning of the year to the date in the current month.
int d = dayOfYear;
if (d < DAYS_JANUARY) {
    return d + 1;
if (d < DAYS_FEBRUARY) {
    return d - (DAYS_JANUARY - 1);
if (leap) {
...
intgetDayOfMonth(int month, int year)
get Day Of Month
int days = 0;
if (month == 2) {
    if (year % 4 != 0) {
        days = 28;
    } else {
        if (year % 100 == 0 && year % 400 != 0) {
            days = 28;
        } else {
...