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

intgetMonthOfYear(final Date date)
Get the month of year by given date.
return getNumberOfGranularity(Calendar.MONTH, date) + 1;
StringgetMonthRate(Date date, boolean moveIn)
get Month Rate
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int day = calendar.get(5);
int daysOfThisMonth = calendar.getActualMaximum(5);
double rate;
if (moveIn)
    rate = (daysOfThisMonth - day + 1) / daysOfThisMonth;
else {
...
intgetMonths(Date date1, Date date2)
get Months
int iMonth = 0;
try {
    Calendar objCalendarDate1 = Calendar.getInstance();
    objCalendarDate1.setTime(date1);
    Calendar objCalendarDate2 = Calendar.getInstance();
    objCalendarDate2.setTime(date2);
    if (objCalendarDate2.equals(objCalendarDate1))
        return 0;
...
DategetMonthStart(Date date)
get Month Start
if (date == null) {
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
...
DategetMonthStart(Date date)
get Month Start
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return calendar.getTime();
DategetMonthStartDay(Date date)
get Month Start Day
Calendar calendar = getCalendar(date);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return calendar.getTime();
DategetNextMonth(Date baseDate, int Month)

Description:Get the date after the base date passed in as first parameter and interval is specified by second parameter

Calendar calendar = Calendar.getInstance();
calendar.setTime(baseDate);
calendar.add(Calendar.MONTH, Month);
Date resultDate = calendar.getTime();
return resultDate;
DategetNextMonth(Date time)
get Next Month
Calendar calendar = Calendar.getInstance();
if (null != time) {
    calendar.setTimeInMillis(time.getTime());
calendar.add(Calendar.MONTH, 1);
return new Date(calendar.getTimeInMillis());
longgetNextMonth(long date)
Returns the next month.
return incrementMonth(date, 1);
DategetNextMonthDate(Date appointDate)
get Next Month Date
Calendar appointCalendar = Calendar.getInstance();
appointCalendar.setTime(appointDate);
Calendar lastDate = Calendar.getInstance();
lastDate.set(Calendar.DATE, appointCalendar.get(Calendar.DATE));
lastDate.set(Calendar.MONTH, appointCalendar.get(Calendar.MONTH) + 1);
lastDate.set(Calendar.YEAR, appointCalendar.get(Calendar.YEAR));
return lastDate.getTime();