Java Utililty Methods Month Day

List of utility methods to do Month Day

Description

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

Method

DateaddMonthsAndDays(Date date, int months, int days)
add Months And Days
Calendar sysDate = new GregorianCalendar();
sysDate.setTime(date);
sysDate.add(Calendar.MONTH, months);
sysDate.add(Calendar.DAY_OF_MONTH, days);
return sysDate.getTime();
voidaddMonthToDayOfMonth(Calendar c, int dayOfMonth, int monthInterval)
add Month To Day Of Month
for (int i = 0; i < monthInterval; i++) {
    c.set(Calendar.DAY_OF_MONTH, 1);
    c.add(Calendar.DATE, 33);
    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    if (c.get(Calendar.DAY_OF_MONTH) != dayOfMonth) {
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.add(Calendar.DAY_OF_MONTH, -1);
intdaysInMonth(GregorianCalendar c)
Here get the number of days in particular month
int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
daysInMonths[1] += c.isLeapYear(c.get(GregorianCalendar.YEAR)) ? 1 : 0;
return daysInMonths[c.get(GregorianCalendar.MONTH)];
DatefirstDayOfMonth(Date date)
first Day Of Month
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DAY_OF_MONTH, 1);
return c.getTime();
DatefirstDayOfMonth(Date date)
first Day Of Month
Calendar cal = calendar(date);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
StringfirstMonthDay(String dateTime, int num)
first Month Day
try {
    Date date = dd.parse(dateTime);
    Calendar now = Calendar.getInstance();
    now.setTime(date);
    int year = now.get(Calendar.YEAR);
    int month = now.get(Calendar.MONTH) - num;
    int day = now.get(Calendar.DAY_OF_MONTH);
    now.set(year, month, day);
...
intgetActualMaximumDayOfMonth(final Date date)
Return maximun number of days in month.
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
StringgetCurMonthFirstDay()
get Cur Month First Day
Calendar cal = Calendar.getInstance();
Date d = new Date();
cal.setTime(d);
cal.set(Calendar.DATE, 1);
return dateFormat(cal.getTime());
intgetCurrentDayOfMonth()
get Current Day Of Month
Calendar c = new GregorianCalendar();
c.setTime(getCurrentDate());
return c.get(Calendar.DAY_OF_MONTH);
StringgetCurretnMonthFirstDay()
get Curretn Month First Day
String current = getCurrentStringDate();
return current.substring(0, 7) + "-01";