Java Utililty Methods Date to Month

List of utility methods to do Date to Month

Description

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

Method

DategetNextMonthExtention(Date dt, Long n)
get Next Month Extention
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
Calendar firstCal = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(),
        1);
if (firstCal.getActualMaximum(Calendar.DAY_OF_MONTH) < cal.get(Calendar.DAY_OF_MONTH)) {
    return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue() + 1, 1)
            .getTime();
} else {
...
DategetNextMonthFirstDate(Date date)
get Next Month First Date
Date tmpdate = getMonthFirstDate(date);
cal.setTime(tmpdate);
cal.add(Calendar.MONTH, 1);
return new Date(cal.getTime().getTime());
DategetNextMonthFirstDay(Date date)
get Next Month First Day
Calendar a = Calendar.getInstance();
a.setTime(date);
a.add(Calendar.MONTH, 1);
a.set(Calendar.DAY_OF_MONTH, 1);
a.set(Calendar.HOUR_OF_DAY, 0);
a.set(Calendar.MINUTE, 0);
a.set(Calendar.SECOND, 0);
return a.getTime();
...
DategetNextMonthPreviousDay(Date date, int month_num)
get Next Month Previous Day
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.MONTH, month_num); 
c.add(Calendar.DAY_OF_MONTH, -1);
return c.getTime();
DategetNextMonthsByStartDate(Date date, int month)
get Next Months By Start Date
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.MONTH, month);
return calendar.getTime();
...
intmonth(Date date)
month
return toCalendar(date).get(Calendar.MONTH) + 1;
intmonth(Date inDate, TimeZone timeZone)
Calcuate the month number (0 - 11) for the given date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(timeZone);
calendar.setTime(inDate);
return calendar.get(Calendar.MONTH);
intmonth(final Date date)
Returns the month from the day, i.e.
return fromDateToCalendar(date).get(MONTH) + 1;
DatemonthBegin(final Date date)
month Begin
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
...
intmonthOf(Date date)
Dates Extracts the month of the given Date starting at 1 (January=1, February=2, ...).
return toCalendar(date).get(Calendar.MONTH) + 1;