fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Ideone app = new Ideone();
  14. app.doIt();
  15. }
  16.  
  17. public void doIt() {
  18. ZoneOffset offset = ZoneOffset.ofHours( -7 );
  19. OffsetDateTime odt = OffsetDateTime.now( offset );
  20. String output1 = odt.toLocalTime().toString();
  21. System.out.println( "Current time in " + offset + ": " + output1 );
  22.  
  23. ZoneId denverTimeZone = ZoneId.of( "America/Denver" );
  24. ZonedDateTime zdt = ZonedDateTime.now( denverTimeZone );
  25. String output2 = zdt.toLocalTime().toString();
  26. System.out.println( "Current time in " + denverTimeZone + ": " + output2 );
  27. }
  28. }
Success #stdin #stdout 0.24s 322240KB
stdin
Standard input is empty
stdout
Current time in -07:00: 19:41:36.525
Current time in America/Denver: 20:41:36.560