Java Utililty Methods Calendar Day

List of utility methods to do Calendar Day

Description

The list of methods to do Calendar Day are organized into topic(s).

Method

booleanisSameDay(Calendar cal1, Calendar cal2)
Determines if two calendar objects represent the same day.
if (cal1 == null || cal2 == null)
    return false;
if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR))
    return false;
if (cal1.get(Calendar.MONTH) != cal2.get(Calendar.MONTH))
    return false;
if (cal1.get(Calendar.DAY_OF_MONTH) != cal2.get(Calendar.DAY_OF_MONTH))
    return false;
...
booleanisSameDay(Calendar cal1, Calendar cal2)
Check to see if two Calendars are on the same Day, by comparing the year, month and date
int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR);
if (year1 == year2) {
    int month1 = cal1.get(Calendar.MONTH);
    int month2 = cal2.get(Calendar.MONTH);
    if (month1 == month2) {
        int day1 = cal1.get(Calendar.DAY_OF_MONTH);
        int day2 = cal2.get(Calendar.DAY_OF_MONTH);
...
booleanisSameDay(Calendar cal1, Calendar cal2)
is Same Day
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
        && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
        && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
booleanisSameDay(Calendar cal1, Calendar cal2)
Returns whether the two specified times are on the same day
if (cal1.get(Calendar.DAY_OF_YEAR) != cal2.get(Calendar.DAY_OF_YEAR)) {
    return false;
if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) {
    return false;
return true;
booleanisSameDay(Calendar cal1, Calendar cal2)

Checks if two calendars represent the same day ignoring time.

if (cal1 == null || cal2 == null) {
    throw new IllegalArgumentException("The dates must not be null");
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
        && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
        && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
booleanisSameDay(Calendar cal1, Calendar cal2)
is Same Day
int year1 = cal1.get(Calendar.YEAR);
int day1 = cal1.get(Calendar.DAY_OF_YEAR);
int year2 = cal2.get(Calendar.YEAR);
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
if (year1 != year2) {
    return false;
if (day1 != day2) {
...
booleanisSameDay(Calendar day1, Calendar day2)
Return true if both calenday date's are of the same day
return datePart(day1).compareTo(datePart(day2)) == 0;
booleanisSameDay(Calendar dayOne, Calendar dayTwo)
is Same Day
return ((dayOne.get(Calendar.DAY_OF_MONTH) == dayTwo.get(Calendar.DAY_OF_MONTH))
        && (dayOne.get(Calendar.MONTH) == dayTwo.get(Calendar.MONTH))
        && (dayOne.get(Calendar.YEAR) == dayTwo.get(Calendar.YEAR)));
booleanisSameDay(Calendar today, Date now)
Returns a boolean indicating whether the given Date is the same day as the day in the calendar.
Calendar temp = (Calendar) today.clone();
startOfDay(temp);
Date start = temp.getTime();
temp.setTime(now);
startOfDay(temp);
return start.equals(temp.getTime());
booleanisSameDay(final Calendar cal1, final Calendar cal2)
is Same Day
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
        && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);