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.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. ZoneId z = ZoneId.of( "America/Los_Angeles" ) ;
  16.  
  17. LocalDate ld = LocalDate.of( 2019 , 2 , 11 ) ;
  18. LocalTime lt = LocalTime.MIN ;
  19. ZonedDateTime zdt = ZonedDateTime.of( ld , lt , z ) ;
  20.  
  21. // Adjust from zoned value to UTC. Same moment, same point on timeline, different wall-clock time.
  22. Instant instant = zdt.toInstant() ;
  23. Clock clock = Clock.fixed( instant , z ) ;
  24.  
  25. // Inject the fixed clock as a dependency.
  26. Instant now = Instant.now( clock ) ;
  27.  
  28. System.out.println( "zdt.toString(): " + zdt ) ;
  29. System.out.println( "instant.toString(): " + instant ) ;
  30. System.out.println( "clock.toString(): " + clock ) ;
  31. System.out.println( "now.toString(): " + now ) ;
  32.  
  33.  
  34. }
  35. }
Success #stdin #stdout 0.27s 2249728KB
stdin
Standard input is empty
stdout
zdt.toString(): 2019-02-11T00:00-08:00[America/Los_Angeles]
instant.toString(): 2019-02-11T08:00:00Z
clock.toString(): FixedClock[2019-02-11T08:00:00Z,America/Los_Angeles]
now.toString(): 2019-02-11T08:00:00Z