List of utility methods to do Calendar Month
Calendar | incrementMonthByVal(Calendar theCal, int val) increment Month By Val Calendar incrementedCalendar = (Calendar) theCal.clone(); int currentDay = incrementedCalendar.get(Calendar.DAY_OF_MONTH); incrementedCalendar.add(Calendar.MONTH, val); incrementedCalendar.set(Calendar.DAY_OF_MONTH, currentDay); int newDay = incrementedCalendar.get(Calendar.DAY_OF_MONTH); if (newDay < currentDay) { incrementedCalendar.roll(Calendar.DAY_OF_MONTH, false); int rolledBackDay = incrementedCalendar.get(Calendar.DAY_OF_MONTH); ... |
int | intToCalendarMonth(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; ... |
boolean | isFirstDayOfMonth(Calendar calendar) is First Day Of Month if (calendar.get(Calendar.DAY_OF_MONTH) == 1) { return true; return false; |
int | lastDayOfMonth(Calendar c) last Day Of Month return c.getActualMaximum(Calendar.DATE);
|
int | month(Calendar calendar) month return calendar.get(Calendar.MONTH) + 1;
|
int | month(Calendar date) month return date.get(Calendar.MONTH) + 1;
|
int | numberOfDaysInMonth(Calendar cal) number Of Days In Month cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.get(Calendar.DAY_OF_MONTH);
...
|
boolean | sameMonth(Calendar one, Calendar two) Returns true if the two given calendars are dated on the same year and month. return one.get(Calendar.MONTH) == two.get(Calendar.MONTH) && sameYear(one, two);
|
void | setDate(Calendar cal, int month, int date) set Date cal.clear(); cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); ... |
void | setDate(Calendar cal, int month, int date, boolean endOfDay) set Date cal.clear();
cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DATE, date);
if (endOfDay) {
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
...
|