code: public static boolean isBetweenHours(long dt, TimeZone tz, int from, int to, int tolerance) 
      {
          long start = 0L;
          long end = 0L;
  
          // If from > to then the "to" date may be in the next day
          //   or the "from" date may be in the previous day, depending
          //   on whether or not it's before or after midnight
          if(from > to)
          {
              // Assume that start is in today and end is in tomorrow
              start = getDateForHour(dt, tz, from, 0);
              end = getDateForHour(dt, tz, to, 1)+(tolerance*1000L);
  
              // If we end up before the start date,
              //   try moving the dates back by a day
              if(dt < start) // move start to yesterday
              {
                  start = getDateForHour(dt, tz, from, -1);
                  end = getDateForHour(dt, tz, to, 0)+(tolerance*1000L);
              }
          }
          else // to > from
          {
              start = getDateForHour(dt, tz, from, 0);
              end = getDateForHour(dt, tz, to, 0)+(tolerance*1000L);
          }
  
          return dt >= start && dt <= end;
      }
docs: Returns <CODE>true</CODE> if the given date is inside the start and end hours.
  @param dt The date to be checked
  @param tz The timezone associated with the date
  @param from The start hour to check that the date is after
  @param to The end hour to check that the date is before
  @param tolerance The tolerance that by the which the date can be outside the range but still be considered inside
  @return <CODE>true</CODE> if the given date is inside the start and end hours