Here you can find the source of betweenInDay(Date date, Date start, Date end)
Parameter | Description |
---|---|
date | a parameter |
start | a parameter |
end | a parameter |
public static boolean betweenInDay(Date date, Date start, Date end)
//package com.java2s; //License from project: LGPL import java.util.Calendar; import java.util.Date; public class Main { /**/*from ww w . ja v a2 s . c om*/ * check id a date in between two other date, but date in range. * * @param date * @param start * @param end * @return */ public static boolean betweenInDay(Date date, Date start, Date end) { return isAfterOrEqualForDay(date, start) && isBeforeOrEqualForDay(date, end); } /** * check if date is after other date, if the day is the same it is ok. */ public static boolean isAfterOrEqualForDay(Date date, Date ref) { if (ref == null) { return true; } Calendar calDate = Calendar.getInstance(); calDate.setTime(date); Calendar calRef = Calendar.getInstance(); calRef.setTime(ref); if (calDate.get(Calendar.YEAR) < calRef.get(Calendar.YEAR)) { return false; } else if (calDate.get(Calendar.YEAR) == calRef.get(Calendar.YEAR)) { if (calDate.get(Calendar.DAY_OF_YEAR) < calRef.get(Calendar.DAY_OF_YEAR)) { return false; } } return true; } /** * check if date is after other date, if the day is the same it is ok. */ public static boolean isBeforeOrEqualForDay(Date date, Date ref) { if (ref == null) { return true; } Calendar calDate = Calendar.getInstance(); calDate.setTime(date); Calendar calRef = Calendar.getInstance(); calRef.setTime(ref); if (calDate.get(Calendar.YEAR) > calRef.get(Calendar.YEAR)) { return false; } else if (calDate.get(Calendar.YEAR) == calRef.get(Calendar.YEAR)) { if (calDate.get(Calendar.DAY_OF_YEAR) > calRef.get(Calendar.DAY_OF_YEAR)) { return false; } } return true; } }