List of utility methods to do Date Compare by Month
boolean | isSameMonth(Date date1, Date date2) Compare the two dates whether are in the same month. if (date1 == null && date2 == null) return true; if (date1 == null || date2 == null) return false; Calendar cal1 = GregorianCalendar.getInstance(); cal1.setTime(date1); Calendar cal2 = GregorianCalendar.getInstance(); cal2.setTime(date2); ... |
boolean | isSameMonth(Date date1, Date date2) is Same Month if (date1 == null || date2 == null) { throw new IllegalArgumentException("The dates must not be null"); Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return isSameDay(cal1, cal2); ... |
boolean | isSameMonth(final Date d1, final Date d2) is Same Month Calendar c1 = Calendar.getInstance();
c1.setTime(d1);
Calendar c2 = Calendar.getInstance();
c2.setTime(d2);
return c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
|
boolean | isSameMonth(final Date date1, final Date date2) is Same Month final Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); final Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) { return false; return cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH); ... |
int | monthsBetween(Date firstDate, Date secondDate) Calculates number of month between two dates. Date before = null; Date after = null; if (firstDate.after(secondDate)) { after = firstDate; before = secondDate; } else { after = secondDate; before = firstDate; ... |
Integer | monthsBetween(final Date von, final Date bis) months Between if (von == null || bis == null) { return null; if (bis.before(von)) { return null; final Calendar calStart = Calendar.getInstance(); calStart.setTime(von); ... |
boolean | sameMonth(Date date1, Date date2) Checks if the two given dates have the same month. if (date1 == null || date2 == null) { return false; return getMonth(date1) == getMonth(date2); |
boolean | sameMonth(Date date1, Date date2) same Month Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(date1);
c2.setTime(date2);
return c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
|
boolean | sameMonth(Date dateOne, Date dateTwo) Test to see if two dates are in the same month if ((dateOne == null) || (dateTwo == null)) { return false; Calendar cal = Calendar.getInstance(); cal.setTime(dateOne); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); cal.setTime(dateTwo); ... |
boolean | sameMonthYear(Date firstDate, Date secondDate) same Month Year Calendar first = Calendar.getInstance();
first.setTime(firstDate);
Calendar second = Calendar.getInstance();
second.setTime(secondDate);
return sameMonthYear(first, second);
|