Here you can find the source of isBetween(Date date, Date d1, Date d2)
Parameter | Description |
---|---|
date | the target date, not null |
d1 | lower threadhold, if null then no lower threadhold |
d2 | higher threadhold, if null then no higher threadhold |
Parameter | Description |
---|---|
NullPointerException | if date is null |
public static boolean isBetween(Date date, Date d1, Date d2)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/* w w w . j av a 2 s . c o m*/ * Check if date is between d1 and d2 * @param date the target date, not null * @param d1 lower threadhold, if null then no lower threadhold * @param d2 higher threadhold, if null then no higher threadhold * @return true if it is between the two threadhold, false other wise * @throws NullPointerException if date is null */ public static boolean isBetween(Date date, Date d1, Date d2) { long time = date.getTime(); long time1; if (d1 != null) { time1 = d1.getTime(); } else { time1 = Long.MIN_VALUE; } long time2; if (d2 != null) { time2 = d2.getTime(); } else { time2 = Long.MAX_VALUE; } return time > Math.min(time1, time2) && time < Math.max(time1, time2); } }