fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.sql.Timestamp ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. ZoneId z = ZoneId.of( "Africa/Tunis" );
  16. LocalDate ld = LocalDate.of( 2023 , Month.JANUARY , 23 );
  17. List < Timestamp > timestamps = List.of(
  18. Timestamp.from( ZonedDateTime.of( ld , LocalTime.MAX , z ).toInstant() ) , // Convert from modern class to legacy class.
  19. Timestamp.from( ZonedDateTime.of( ld , LocalTime.MIN , z ).toInstant() ) ,
  20. Timestamp.from( ZonedDateTime.of( ld , LocalTime.NOON , z ).toInstant() )
  21. );
  22. var latestTimestamp = timestamps.stream().max( Timestamp :: compareTo );
  23.  
  24. System.out.println( "latestTimestamp.toString() = " + latestTimestamp ) ;
  25. }
  26. }
Success #stdin #stdout 0.21s 55672KB
stdin
Standard input is empty
stdout
latestTimestamp.toString() = Optional[2023-01-23 22:59:59.999999999]