fork download
  1. import java.time.*;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. class Main {
  6. public static void main(String[] args) {
  7. // A sample epoch
  8. long epoch = 1693773531L;
  9.  
  10. // Note: change the timezone as per your requirement
  11. ZoneId userZone = ZoneId.of("America/New_York");
  12.  
  13. ZonedDateTime zdtGiven = Instant.ofEpochSecond(epoch).atZone(userZone);
  14.  
  15. // Today
  16. LocalDate today = LocalDate.now(userZone);
  17.  
  18. // Get start of today
  19. ZonedDateTime startOfToday = today.atStartOfDay(userZone);
  20.  
  21. // Get start of the next day
  22. ZonedDateTime startOfNextDay = today.plusDays(1).atStartOfDay(userZone);
  23.  
  24. if (zdtGiven.isAfter(startOfToday) && zdtGiven.isBefore(startOfNextDay))
  25. // Do this e.g.
  26. System.out.println("Before");
  27. }
  28. }
Success #stdin #stdout 0.15s 39556KB
stdin
Standard input is empty
stdout
Before