fork(1) 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.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. String input = "02-JAN-19 03.34.33.540260000 AM" ;
  17.  
  18. DateTimeFormatterBuilder builder =
  19. new DateTimeFormatterBuilder()
  20. .parseCaseInsensitive()
  21. .appendPattern(
  22. "dd-MMM-uu hh.mm.ss.SSSSSSSSS a"
  23. ) ;
  24. DateTimeFormatter f = builder.toFormatter( Locale.US ) ;
  25. LocalDateTime ldt = LocalDateTime.parse( input , f ) ;
  26.  
  27. ZoneId z = ZoneId.of( "America/Chicago" ) ;
  28. ZonedDateTime zdt = ldt.atZone( z ) ;
  29.  
  30. Instant instant = zdt.toInstant() ;
  31.  
  32. System.out.println( "ldt.toString(): " + ldt ) ;
  33. System.out.println( "zdt.toString(): " + zdt ) ;
  34. System.out.println( "instant.toString(): " + instant ) ;
  35. }
  36. }
Success #stdin #stdout 0.2s 2184192KB
stdin
Standard input is empty
stdout
ldt.toString(): 2019-01-02T03:34:33.540260
zdt.toString(): 2019-01-02T03:34:33.540260-06:00[America/Chicago]
instant.toString(): 2019-01-02T09:34:33.540260Z