Here you can find the source of isBetween(Date check, Date from, Date to)
Parameter | Description |
---|---|
check | is the date to check |
from | is the beginning range of the Date/Time |
to | is the ending range of the Date/Time |
public static boolean isBetween(Date check, Date from, Date to)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { private static boolean bypassTodayCheck; /**/*from w w w . j a va2 s. c o m*/ * Used to check if a date is within a given range * * @param check is the date to check * @param from is the beginning range of the Date/Time * @param to is the ending range of the Date/Time * @return */ public static boolean isBetween(Date check, Date from, Date to) { if (bypassTodayCheck) return true; if (null == check || null == from || null == to) return false; Calendar start = new GregorianCalendar(); start.setTime(from); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); start.add(Calendar.SECOND, -1); Calendar end = new GregorianCalendar(); end.setTime(to); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 999); end.add(Calendar.MILLISECOND, 1); Calendar checkCal = new GregorianCalendar(); checkCal.setTime(check); checkCal.set(Calendar.HOUR, 12); return start.before(checkCal) && end.after(checkCal); } }