fork(2) 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. LocalDate ld = LocalDate.now( ZoneId.of( "America/Montreal" ) );
  16. LocalDate xmasThisYear = MonthDay.of( Month.DECEMBER , 25 ).atYear( ld.getYear() );
  17. ZoneId earliestXmasZone = ZoneId.of( "Pacific/Kiritimati" ) ;
  18. ZonedDateTime zdtEarliestXmasThisYear = xmasThisYear.atStartOfDay( earliestXmasZone );
  19. Instant instantEarliestXmasThisYear = zdtEarliestXmasThisYear.toInstant();
  20. Clock clockEarliestXmasThisYear = Clock.fixed( instantEarliestXmasThisYear , earliestXmasZone );
  21.  
  22. // Use that special fixed clock to always return the same moment.
  23. Instant instant = Instant.now( clockEarliestXmasThisYear );
  24. ZonedDateTime zdt = ZonedDateTime.now( clockEarliestXmasThisYear );
  25. ZonedDateTime zdtMontreal = zdt.withZoneSameInstant( ZoneId.of ( "America/Montreal" ) ) ;
  26.  
  27. System.out.println( "instant.toString(): " + instant );
  28. System.out.println( "zdt.toString(): " + zdt );
  29. System.out.println( "zdtMontreal.toString(): " + zdtMontreal );
  30.  
  31. }
  32. }
Success #stdin #stdout 0.15s 321280KB
stdin
Standard input is empty
stdout
instant.toString(): 2016-12-24T10:00:00Z
zdt.toString(): 2016-12-25T00:00+14:00[Pacific/Kiritimati]
zdtMontreal.toString(): 2016-12-24T05:00-05:00[America/Montreal]