Here you can find the source of todayOnOrBetween(Date startDate, Date endDate)
Parameter | Description |
---|---|
startDelegation | a parameter |
endDelegation | a parameter |
public static boolean todayOnOrBetween(Date startDate, Date endDate)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**/*from w w w . ja v a 2 s. c om*/ * @param startDelegation * @param endDelegation * @return */ public static boolean todayOnOrBetween(Date startDate, Date endDate) { Date today = new Date(); if ((isSameDate(today, startDate) || today.after(startDate) && (isSameDate(today, endDate) || today.before(endDate)))) { return true; } return false; } /** * Returns true if the 2 dates are the same, regardless of the time * * @param date1 * @param date2 * @return */ public static boolean isSameDate(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; } Calendar c1 = (GregorianCalendar) Calendar.getInstance(); c1.setTime(date1); c1.set(Calendar.HOUR_OF_DAY, 0); c1.set(Calendar.MINUTE, 0); c1.set(Calendar.SECOND, 0); c1.set(Calendar.MILLISECOND, 0); Calendar c2 = (GregorianCalendar) Calendar.getInstance(); c2.setTime(date2); c2.set(Calendar.HOUR_OF_DAY, 0); c2.set(Calendar.MINUTE, 0); c2.set(Calendar.SECOND, 0); c2.set(Calendar.MILLISECOND, 0); return c1.equals(c2); } }