List of utility methods to do Month Calculate
Map | getMonthsMap() Returns a map of months return monthNames;
|
int | getMonthsOfAge(Date birth, Date now) get Months Of Age Calendar nowCalendar = new GregorianCalendar(); Calendar birthCalendar = new GregorianCalendar(); birthCalendar.setTime(birth); nowCalendar.setTime(now); if (nowCalendar.getTimeInMillis() > birthCalendar.getTimeInMillis()) { int months = nowCalendar.get(Calendar.MONTH) - birthCalendar.get(Calendar.MONTH); int yearDiff = nowCalendar.get(Calendar.YEAR) - birthCalendar.get(Calendar.YEAR); if (yearDiff > 0) { ... |
int | getMonthSpan(Date begin, Date end) get Month Span Calendar beginCal = new GregorianCalendar(); beginCal.setTime(begin); Calendar endCal = new GregorianCalendar(); endCal.setTime(end); int m = (endCal.get(Calendar.MONTH)) - (beginCal.get(Calendar.MONTH)); int y = (endCal.get(Calendar.YEAR)) - (beginCal.get(Calendar.YEAR)); return y * 12 + m; |
long | getNextMonth(long date) Returns the next month. return incrementMonth(date, 1);
|
Date | getNextMonthExtention(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 { ... |
String | getNowMonth() get Now Month Date date = new Date(); int year = date.getYear() + 1900; int month = date.getMonth() + 1; return year + "-" + (month < 10 ? "0" : "") + month; |
Calendar | getStartOfMonth(Calendar scal) Converts a calendar to the first day of the month scal.add(Calendar.DAY_OF_MONTH, -(scal.get(Calendar.DAY_OF_MONTH) - 1));
return scal;
|
String | getThisMonthEnd() get This Month End String strY = null; String strZ = null; boolean leap = false; Calendar localTime = Calendar.getInstance(); int x = localTime.get(Calendar.YEAR); int y = localTime.get(Calendar.MONTH) + 1; if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) { strZ = "31"; ... |
String | getThisMonthStart() get This Month Start String strY = null; Calendar localTime = Calendar.getInstance(); int x = localTime.get(Calendar.YEAR); int y = localTime.get(Calendar.MONTH) + 1; strY = y >= 10 ? String.valueOf(y) : ("0" + y); return x + "-" + strY + "-01"; |
long | incrementMonth(long date, int increment) increment Month Calendar calendar = CALENDAR; synchronized (calendar) { calendar.setTimeInMillis(date); calendar.add(Calendar.MONTH, increment); return calendar.getTimeInMillis(); |