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.temporal.*;
  9. import java.time.format.*;
  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. String input = "2017-01-17 01:33:00" ;
  18.  
  19. DateTimeFormatter f = DateTimeFormatter.ofPattern( "yyyy-MM-dd HH:mm:ss" ) ;
  20. LocalDateTime ldt = LocalDateTime.parse( input , f ) ;
  21. OffsetDateTime utc = ldt.atOffset( ZoneOffset.UTC ) ;
  22.  
  23. ZoneOffset offset = ZoneOffset.of( "-04:33" ) ;
  24. OffsetDateTime odt = utc.withOffsetSameInstant( offset ) ;
  25.  
  26. System.out.println( "input: " + input ) ;
  27. System.out.println( "ldt.toString(): " + ldt ) ;
  28. System.out.println( "utc.toString(): " + utc ) ;
  29. System.out.println( "odt.toString(): " + odt ) ;
  30.  
  31. }
  32. }
Success #stdin #stdout 0.16s 4386816KB
stdin
Standard input is empty
stdout
input: 2017-01-17 01:33:00
ldt.toString(): 2017-01-17T01:33
utc.toString(): 2017-01-17T01:33Z
odt.toString(): 2017-01-16T21:00-04:33