Here you can find the source of isInRange(Date myDate, Date dateStart, Date dateEnd)
Parameter | Description |
---|---|
myDate | Date to compare |
dateStart | Range Start Date |
dateEnd | Range End Date |
public static boolean isInRange(Date myDate, Date dateStart, Date dateEnd)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**/* w w w . j ava 2 s. c o m*/ * Is the date given in date range * @param myDate Date to compare * @param dateStart Range Start Date * @param dateEnd Range End Date * @return */ public static boolean isInRange(Date myDate, Date dateStart, Date dateEnd) { return isInSameDayOrAfter(myDate, dateStart) && isInSameDayOrBefore(myDate, dateEnd); } public static boolean isInSameDayOrAfter(Date d1, Date d2) { if (d1 == null || d2 == null) return false; if (isInSameDay(d1, d2) || d1.after(d2)) return true; return false; } public static boolean isInSameDayOrBefore(Date d1, Date d2) { if (d1 == null || d2 == null) return false; if (isInSameDay(d1, d2) || d1.before(d2)) return true; return false; } /** Returns true if the Dates are in the same day. Ignores time. * @param d1 Day one compared to * @param d2 Day two * @return */ public static boolean isInSameDay(Date d1, Date d2) { if (d1 == null || d2 == null) { return false; } GregorianCalendar cal1 = new GregorianCalendar(); cal1.setTime(d1); GregorianCalendar cal2 = new GregorianCalendar(); cal2.setTime(d2); return (cal1.get(Calendar.DATE) == cal2.get(Calendar.DATE) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)); } }