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.  
  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.  
  18. String input = "2017-03-12 02:46:00".replace( " " , "T" );
  19. LocalDateTime ldt = LocalDateTime.parse( input );
  20. ZoneId z = ZoneId.of( "America/Los_Angeles" );
  21. ZonedDateTime zdt = ldt.atZone( z );
  22.  
  23. System.out.println( "input: " + input );
  24. System.out.println( "ldt.toString(): " + ldt );
  25. System.out.println( "zdt.toString(): " + zdt );
  26.  
  27. }
  28. }
Success #stdin #stdout 0.11s 712192KB
stdin
Standard input is empty
stdout
input: 2017-03-12T02:46:00
ldt.toString(): 2017-03-12T02:46
zdt.toString(): 2017-03-12T03:46-07:00[America/Los_Angeles]