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

StringgetCurrentMonthName()
get Current Month Name
return MONTH_NAMES[getCurrentMonth() - 1];
DategetDateMonthShift(int Shift)
get Date Month Shift
Calendar tempcalendar = GregorianCalendar.getInstance();
tempcalendar.setTime(gamedate);
tempcalendar.add(Calendar.MONTH, Shift);
return tempcalendar.getTime();
intgetDiffInMonths(Date firstDate, Date lastDate)
get Diff In Months
Calendar cFirst = new GregorianCalendar();
cFirst.setTime(firstDate);
Calendar cLast = new GregorianCalendar();
cLast.setTime(lastDate);
int cFirst_year = cFirst.get(Calendar.YEAR);
int cFirst_month = cFirst.get(Calendar.MONTH);
int cLast_year = cLast.get(Calendar.YEAR);
int cLast_month = cLast.get(Calendar.MONTH);
...
StringgetDisplayMonth(int month)
get Display Month
return monthStrings[month];
intgetIntMonthShift(Date Shift)
get Int Month Shift
Calendar tempcalendar1 = GregorianCalendar.getInstance();
Calendar tempcalendar2 = GregorianCalendar.getInstance();
tempcalendar1.setTime(Shift);
tempcalendar2.setTime(gamedate);
int month1 = tempcalendar1.get(Calendar.MONTH);
int month2 = tempcalendar2.get(Calendar.MONTH);
month1 = month1 + 12 * (tempcalendar1.get(Calendar.YEAR) - tempcalendar2.get(Calendar.YEAR));
return month1 - month2;
...
intgetlastDateofThisMonth()
getlast Dateof This Month
return getlastDateofThisMonth(-1, -1);
DategetLastMonthBegin()
get Last Month Begin
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
...
StringgetMonthFormat(String date)
get Month Format
date = deleteDash(date);
return (date.substring(0, 4) + "-" + date.substring(4, 6));
ListgetMonthlyIntervals(Date start, Date end)
get Monthly Intervals
List<Date> intervals = new ArrayList<Date>();
GregorianCalendar c = new GregorianCalendar();
c.setTime(start);
int startMonth = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
int month = startMonth;
intervals.add(start);
while (true) {
...
StringgetMonthNumber()
get Month Number
Calendar calendar = new GregorianCalendar();
int m = calendar.get(GregorianCalendar.MONTH);
String month = new Integer(m + 1).toString();
if (month.length() < 2)
    month = "0" + month;
return month;