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

StringcurrentMonthFirstDay()
current Month First Day
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
Date curDate = new Date(System.currentTimeMillis());
Calendar calendar = Calendar.getInstance();
calendar.setTime(curDate);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return sdf.format(calendar.getTime());
intdayForMonth(String pTime)
day For Month
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(format.parse(pTime));
int m = c.get(Calendar.DAY_OF_MONTH);
return m;
intdaysInMonth(int month, boolean isLeapYear)
days In Month
int i = (month - 1) + 12 * (isLeapYear ? 1 : 0);
return DAYS_IN_MONTH[i];
intdaysInMonth(int month, int year)
return the number of days in the month of the year.
return daysInMonth[isLeapYear(year) ? 1 : 0][month];
intdaysInMonth(int year, int month)
days In Month
int daysInMonth;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
...
int[]daysOfMonth(int year)
days Of Month
if (isLeapYear(year)) {
    return DAYS_OF_MONTH_IN_LEAP_YEAR;
return DAYS_OF_MONTH_IN_NORMAL_YEAR;
intdaysOfMonth(int year, int month)
days Of Month
int days = 0;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
...
StringfirstDayOfLastMonth()
first Day Of Last Month
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.DATE, 1);
return String.valueOf(dfDdMMMYYYY.format(cal.getTime()));
intfirstDayOfMonth(int commonMonthIndx, int iyear)
first Day Of Month
return ((commonMonthIndx > 2) ? leapYearBalance(iyear) : 0) + FirstDayOfMonth[commonMonthIndx - 1];
StringfirstDayOfMonth(int year, int month, String dateFormat)
get first day of specified month and specified year in specified date format.
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.YEAR, year);
cal.add(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, 1);
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
return formatter.format(cal.getTime());