Caveat: I do not know JavaMail, and don’t understand the exact behavior of ReceivedDateTerm
. But I do know date-time handling. If the goal is determine the first moment of today, read on.
First moment of day
Your date-time handling is incorrect.
The modern approach uses the java.time classes defined in JSR 310.
Getting the current date requires a time zone. For any given moment, the date varies around the globe by zone.
ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
LocalDate today = LocalDate.now( z ) ;
Determine the first moment. Not necessarily the time 00:00:00 as some dates in some zones start at another time such as 01:00:00.
ZonedDateTime zdt = today.atStartOfDay( z ) ;
Extract an Instant
to adjust into UTC. Same moment, same point on the timeline, different wall-clock time.
Instant instant = zdt.toInstant() ;
The constructor for ReceivedDateTerm
takes a java.util.Date
object, having not yet been updated to the modern java.time framework.
Convert from our modern Instant
to the terrible and misnamed legacy class java.util.Date
.
Date d = Date.from( instant ) ;
Pass d
to your JavaMail code as the starting moment for your search.