Here you can find the source of isAfterDay(Calendar cal1, Calendar cal2)
Checks if the first calendar date is after the second calendar date 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 of the calendars are<code>null</code> |
public static boolean isAfterDay(Calendar cal1, Calendar cal2)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { /**/*w w w . ja v a2 s . c o m*/ * <p> * Checks if the first date is after the second date ignoring time. * </p> * * @param date1 the first date, not altered, not null * @param date2 the second date, not altered, not null * @return true if the first date day is after the second date day. * @throws IllegalArgumentException if the date is <code>null</code> */ public static boolean isAfterDay(Date date1, Date date2) { 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 isAfterDay(cal1, cal2); } /** * <p> * Checks if the first calendar date is after the second calendar date * ignoring time. * </p> * * @param cal1 the first calendar, not altered, not null. * @param cal2 the second calendar, not altered, not null. * @return true if cal1 date is after cal2 date ignoring time. * @throws IllegalArgumentException if either of the calendars are * <code>null</code> */ public static boolean isAfterDay(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The dates must not be null"); } if (cal1.get(Calendar.ERA) < cal2.get(Calendar.ERA)) return false; if (cal1.get(Calendar.ERA) > cal2.get(Calendar.ERA)) return true; if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) return false; if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR)) return true; return cal1.get(Calendar.DAY_OF_YEAR) > cal2.get(Calendar.DAY_OF_YEAR); } }