Java Utililty Methods Month Calculate

List of utility methods to do Month Calculate

Description

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

Method

intintToCalendarMonth(int month)
int To Calendar Month
if (month == 1) {
    return Calendar.JANUARY;
} else if (month == 2) {
    return Calendar.FEBRUARY;
} else if (month == 3) {
    return Calendar.MARCH;
} else if (month == 4) {
    return Calendar.APRIL;
...
booleanisFirstOfMonth(long date)
is First Of Month
boolean ret = false;
Calendar calendar = CALENDAR;
synchronized (calendar) {
    calendar.setTimeInMillis(date);
    int currentMonth = calendar.get(Calendar.MONTH);
    calendar.add(Calendar.DATE, -1);
    int yesterdayMonth = calendar.get(Calendar.MONTH);
    ret = (currentMonth != yesterdayMonth);
...
booleanisMonthEnd(Date date)
is Month End
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (cal.get(Calendar.DATE) == cal.getActualMaximum(Calendar.DAY_OF_MONTH))
    return true;
else
    return false;
booleanisSameMonth(final Calendar c1, final Calendar c2)
is Same Month
return c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
intmonthsBetween(String pFormerStr, String pLatterStr)
months Between
GregorianCalendar vFormer = parse2Cal(pFormerStr);
GregorianCalendar vLatter = parse2Cal(pLatterStr);
return monthsBetween(vFormer, vLatter);
DatenextMonth(Date date, int months)
next Month
Calendar cal = Calendar.getInstance();
if (date != null) {
    cal.setTime(date);
cal.add(Calendar.MONTH, months);
return cal.getTime();
DatenextMonths(int diff)
next Months
return add(new Date(), Calendar.MONTH, diff);
CalendarstartOfMonth(Date d)
start Of Month
Calendar c = new GregorianCalendar();
c.setTime(d);
int yy = c.get(Calendar.YEAR);
int mm = c.get(Calendar.MONTH);
c = new GregorianCalendar(yy, mm, 1);
return c;
DatestartOfMonth(Date date)
start Of Month
if (date == null) {
    return null;
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, 1);
return cal.getTime();
DatestartOfMonthDate(Date date)
start Of Month Date
Calendar now = Calendar.getInstance();
now.setTime(date);
now.set(Calendar.DAY_OF_MONTH, 1);
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
return now.getTime();
...