DateUtils { public static boolean isToday( Date date ) { int days = Days.daysBetween( new LocalDate( date ), new LocalDate() ).getDays(); return days == 0; }  static String getIso8601( Date date ); static String getIso8601NoTz( Date date ); static String getLongGmtDateString( Date date ); static String getLongDateString( Date date ); static String getLongDateString(); static String getMediumDateString( Date date ); static String getMediumDateString(); static String getHttpDateString( Date date ); static Date max( Date date1, Date date2 ); static Date max( Collection<Date> dates ); static Date min( Date date1, Date date2 ); static Date min( Collection<Date> dates ); static Date getMediumDate( String string ); static boolean between( Date baseDate, Date startDate, Date endDate ); static boolean strictlyBetween( Date baseDate, Date startDate, Date endDate ); static long getDays( Date date ); static long getDays( Date startDate, Date endDate ); static long getDaysInclusive( Date startDate, Date endDate ); static int daysBetween( Date startDate, Date endDate ); static boolean isToday( Date date ); static int monthsBetween( Date startDate, Date endDate ); static int daysSince1900( Date date ); static Date getNextDate( int hourOfDay, Date now ); static Date getEpoch(); static String getSqlDateString( Date date ); static boolean dateIsValid( String dateString ); static boolean dateIsValid( org.hisp.dhis.calendar.Calendar calendar, String dateString ); static boolean dateTimeIsValid( final String dateTimeString ); static long getSecondsUntilTomorrow( int hour ); static Date getDateForTomorrow( int hour ); static Date getDateAfterAddition( Date date, int days ); static Date calculateDateFrom( final Date date, final int addend, final int chronoUnit ); static List<Period> setNames( List<Period> periods, I18nFormat format ); static String getPrettyInterval( Date start, Date end ); static String getPrettyInterval( long ms ); static Date parseDate( final String dateString ); static Date getDate( LocalDateTime time ); static Date nowMinusDuration( String duration ); static Duration getDuration( String duration ); static Timestamp asTimestamp( Date date ); static java.sql.Date asSqlDate( Date date ); static Date getLatest( Date... dates ); static Date removeTimeStamp( Date date ); static final PeriodFormatter DAY_SECOND_FORMAT; static final double DAYS_IN_YEAR; }
@Test public void testIsToday() { java.util.Calendar cal = java.util.Calendar.getInstance(); Date today = cal.getTime(); cal.add( DATE, -1 ); Date yesterday = cal.getTime(); cal.add( DATE, +2 ); Date tomorrow = cal.getTime(); assertTrue( DateUtils.isToday( today ) ); assertFalse( DateUtils.isToday( yesterday ) ); assertFalse( DateUtils.isToday( tomorrow ) ); }