Java Calendar Day isSameDay(Calendar cal1, Calendar cal2)

Here you can find the source of isSameDay(Calendar cal1, Calendar cal2)

Description

Checks if two calendars represent the same day ignoring time.

License

Open Source License

Parameter

Parameter Description
cal1 the first calendar, not altered, not null
cal2 the second calendar, not altered, not null

Exception

Parameter Description
IllegalArgumentException if either calendar is <code>null</code>

Return

true if they represent the same day

Declaration

public static boolean isSameDay(Calendar cal1, Calendar cal2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    /**/*from  w w w.  j a  va  2 s  .co  m*/
     * <p>
     * Checks if two calendars represent the same day ignoring time.
     * </p>
     * 
     * @param cal1
     *            the first calendar, not altered, not null
     * @param cal2
     *            the second calendar, not altered, not null
     * @return true if they represent the same day
     * @throws IllegalArgumentException
     *             if either calendar is <code>null</code>
     */
    public static boolean isSameDay(Calendar cal1, Calendar cal2) {
        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));
    }
}

Related

  1. isSameDay(Calendar cal1, Calendar cal2)
  2. isSameDay(Calendar cal1, Calendar cal2)
  3. isSameDay(Calendar cal1, Calendar cal2)
  4. isSameDay(Calendar cal1, Calendar cal2)
  5. isSameDay(Calendar cal1, Calendar cal2)
  6. isSameDay(Calendar cal1, Calendar cal2)
  7. isSameDay(Calendar day1, Calendar day2)
  8. isSameDay(Calendar dayOne, Calendar dayTwo)
  9. isSameDay(Calendar today, Date now)