fork(1) 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.time.temporal.*;
  9. import java.time.format.*;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. java.util.Date myJavaUtilDate1 = java.util.Date.from ( Instant.now ( ) );
  18. java.util.Date myJavaUtilDate2 = java.util.Date.from ( Instant.now ( ).minus ( 6, ChronoUnit.HOURS ) );
  19.  
  20. Instant instant1 = myJavaUtilDate1.toInstant ( );
  21. Instant instant2 = myJavaUtilDate2.toInstant ( );
  22.  
  23. ZoneId z = ZoneId.of ( "America/Montreal" );
  24.  
  25. ZonedDateTime zdt1 = instant1.atZone ( z );
  26. ZonedDateTime zdt2 = instant2.atZone ( z );
  27.  
  28. LocalDate localDate1 = zdt1.toLocalDate ( );
  29. LocalDate localDate2 = zdt2.toLocalDate ( );
  30. Boolean sameDate = localDate1.isEqual ( localDate2 );
  31.  
  32. System.out.println ( "instant1: " + instant1 + " | instant2: " + instant2 );
  33. System.out.println ( "zdt1: " + zdt1 + " | zdt2: " + zdt2 );
  34. System.out.println ( "localDate1: " + localDate1 + " | localDate2: " + localDate2 );
  35. System.out.println ( "sameDate: " + sameDate );
  36.  
  37. }
  38. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
instant1: 2017-03-25T04:20:12.733Z | instant2: 2017-03-24T22:20:12.733Z
zdt1: 2017-03-25T00:20:12.733-04:00[America/Montreal] | zdt2: 2017-03-24T18:20:12.733-04:00[America/Montreal]
localDate1: 2017-03-25 | localDate2: 2017-03-24
sameDate: false