Here you can find the source of isSameDay(Calendar cal1, Calendar cal2)
Checks if two calendars represent the same day ignoring time.
Parameter | Description |
---|---|
cal1 | the first calendar, not altered, not null |
cal2 | the second calendar, not altered, not null |
Parameter | Description |
---|---|
IllegalArgumentException | if either calendar is <code>null</code> |
public static boolean isSameDay(Calendar cal1, Calendar cal2)
//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)); } }