title: get the nearest date closest to temp date
body: <p>I have two date fields:</p>
  <p>start date <code>(2021-03-07T07:37:15)</code> and end date <code>(2021-03-07T07:37:25)</code> and temp date <code>(2021-03-07T07:37:20)</code> .</p>
  <p>I have a list where I have returned 6 records between the start date and end date. How can I filter the records and return the datetime which is closest to temp date?</p>
  <p>here in the example records I need to get the 2nd record because the <code>2021-03-07T07:37:19.999</code> is closet to the temp date.
  Example</p>
  <pre><code>    2021-03-07T07:37:15.000
      2021-03-07T07:37:19.999
      2021-03-07T07:37:20.000
      2021-03-07T07:37:20.809
      2021-03-07T07:37:22.100
      2021-03-07T07:37:22.814
  </code></pre>
  <pre><code>     public RequiredRecord findCloseRecord(List&lt;RequiredRecord &gt; list,  Date tempDate) {
  Date startTime  = new Date(tempDate.getTime() - 5000);  
      Date endTime = new Date(tempDate.getTime() + 5000);
            Log.logInfo(this, &quot;Find close record&quot;);
            if (list != null &amp;&amp; !list.isEmpty()) {
                 List&lt;RequiredRecord &gt; filteredRec = list.stream()
                           .filter(rec -&gt; (rec.getLogRecDateTime() != null ))
                           .sorted(Comparator.comparing(RequiredRecord ::getLogRecDateTime))
                           .collect(Collectors.toList());    
            
                 if (!ClrUtils.isCollectionEmpty(filteredRec)) {
                      return (RequiredRecord ) (filteredRec);
                 }
            }
            return null;
       }
  </code></pre>