Java Utililty Methods Day of Month

List of utility methods to do Day of Month

Description

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

Method

DategetLastDayOfMonth(int year, int month)
get Last Day Of Month
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
...
StringgetLastDayOfMonth(int year, int month)
get Last Day Of Month
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
cal.set(Calendar.DAY_OF_MONTH, 1);
int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, value);
StringBuffer sb = new StringBuffer();
String date = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
...
StringgetLastDayOfMonth(int year, int month)
get the last date of given month and year
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DATE, 1);
calendar.add(Calendar.MONTH, 1);
calendar.add(Calendar.DAY_OF_YEAR, -1);
return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
        + calendar.get(Calendar.DAY_OF_MONTH);
...
StringgetLastDayOfMonth(int year, int month)
get Last Day Of Month
Calendar c = Calendar.getInstance();
c.set(year, month, 1, 0, 0, 0);
c.add(Calendar.MONTH, -1);
c.set(Calendar.DAY_OF_MONTH, c.getMaximum(Calendar.DAY_OF_MONTH));
SimpleDateFormat sdf = new SimpleDateFormat(FORMAT);
return sdf.format(c.getTime());
IntegergetLastDayOfMonth(int year, int month)
get Last Day Of Month
return intDateSub(getIntDate(newCalendar(year, month + 1, 1)), 1);
StringgetLastDayOfMonth(int year, int month)
get Last Day Of Month
int m = month;
if (m > 12)
    m = 12;
if (m < 1)
    m = 1;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, m - 1);
...
intgetLastDayOfMonth(int year, int month)
get Last Day Of Month
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
int value = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, value);
return calendar.get(Calendar.DAY_OF_MONTH);
DategetLastDayOfMonth(int year, int month)
Return last day of date with specified year and month
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
int lastDay = cal.getActualMaximum(Calendar.DATE);
cal.set(Calendar.DAY_OF_MONTH, lastDay);
return cal.getTime();
java.util.DategetLastDayOfMonth(java.util.Date date)
getLastDayOfMonth: returns the last day of the given dates month
date = addMonths(date, 1);
return addDays(getFirstDayOfMonth(date), -1);
StringgetLastDayOfMonth(String year, String month)
get last day of month
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(year));
cal.set(Calendar.MONTH, Integer.parseInt(month) - 1);
cal.set(Calendar.DATE, 1);
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DATE, -1);
return String.valueOf(cal.get(Calendar.DAY_OF_MONTH));