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.time.format.* ;
  9. import java.time.temporal.* ;
  10. import java.time.chrono.* ;
  11. import java.time.zone.* ;
  12.  
  13.  
  14. /* Name of the class has to be "Main" only if the class is public. */
  15. class Ideone
  16. {
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. Instant a = Instant.parse("2020-06-09T07:10:28.1985307Z");
  20. Instant b = Instant.parse("2020-04-09T07:10:28.1985307Z");
  21. Instant c = Instant.parse("2020-06-09T23:10:28.1985307Z");
  22.  
  23. ZoneId zoneId = ZoneId.of( "Europe/Amsterdam" );
  24.  
  25. LocalDate aDate = extractLocalDateByZone( a , zoneId );
  26. LocalDate bDate = extractLocalDateByZone( b , zoneId );
  27. LocalDate cDate = extractLocalDateByZone( c , zoneId );
  28.  
  29. System.out.println( "Notice how the dates differ after adjusting into another time zone…" ) ;
  30. System.out.println( "aDate.toString(): " + aDate ) ;
  31. System.out.println( "cDate.toString(): " + cDate ) ;
  32. System.out.println( aDate.isEqual( cDate ) ) ;
  33. }
  34.  
  35. public static LocalDate extractLocalDateByZone( Instant i , ZoneId zone ) {
  36. return i.atZone(zone).toLocalDate();
  37. }
  38. }
Success #stdin #stdout 0.14s 39140KB
stdin
Standard input is empty
stdout
Notice how the dates differ after adjusting into another time zone…
aDate.toString(): 2020-06-09
cDate.toString(): 2020-06-10
false