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 = "2018-12-31-12.30.50.000200" ;
  18. DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuuu-MM-dd-HH.mm.ss.SSSSSS" ) ;
  19. LocalDateTime ldt = LocalDateTime.parse( input , f ) ;
  20.  
  21. ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
  22. ZonedDateTime zdt = ldt.atZone( z ) ;
  23.  
  24. Instant instant = zdt.toInstant() ;
  25.  
  26. System.out.println( "input: " + input ) ;
  27. System.out.println( "ldt: " + ldt ) ;
  28. System.out.println( "zdt: " + zdt ) ;
  29. System.out.println( "instant: " + instant ) ;
  30.  
  31. }
  32. }
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
input: 2018-12-31-12.30.50.000200
ldt: 2018-12-31T12:30:50.000200
zdt: 2018-12-31T12:30:50.000200+09:00[Asia/Tokyo]
instant: 2018-12-31T03:30:50.000200Z