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 = "20190310022817";
  18. DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuuuMMddHHmmss" ) ;
  19. LocalDateTime ldt = LocalDateTime.parse( input , f ) ;
  20.  
  21. ZoneId zParis = ZoneId.of( "Europe/Paris" ) ;
  22. ZonedDateTime zdtParis = ldt.atZone( zParis ) ;
  23.  
  24. ZoneId zNewYork = ZoneId.of( "America/New_York" ) ;
  25. ZonedDateTime zdtNewYork = ldt.atZone( zNewYork ) ;
  26.  
  27. System.out.println( "ldt.toString(): " + ldt ) ;
  28. System.out.println( "zdtParis.toString(): " + zdtParis ) ;
  29. System.out.println( "zdtNewYork.toString(): " + zdtNewYork ) ;
  30.  
  31. System.out.println(
  32.  
  33. LocalDateTime
  34. .parse(
  35. "20190310022817" ,
  36. DateTimeFormatter.ofPattern( "uuuuMMddHHmmss" )
  37. )
  38. .atZone(
  39. ZoneId.of( "America/Montreal" )
  40. )
  41.  
  42. );
  43. }
  44. }
Success #stdin #stdout 0.18s 2249728KB
stdin
Standard input is empty
stdout
ldt.toString(): 2019-03-10T02:28:17
zdtParis.toString(): 2019-03-10T02:28:17+01:00[Europe/Paris]
zdtNewYork.toString(): 2019-03-10T03:28:17-04:00[America/New_York]
2019-03-10T03:28:17-04:00[America/Montreal]