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. import java.time.chrono.* ;
  11.  
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. String input = "Wed Jan 15 14:29:00 2020" ;
  19. DateTimeFormatter f = DateTimeFormatter.ofPattern( "EEE MMM d HH:mm:ss uuuu" ).withLocale( Locale.US ) ;
  20. LocalDateTime ldt = LocalDateTime.parse( input , f ) ;
  21. System.out.println( "ldt.toString: " + ldt ) ;
  22.  
  23. OffsetDateTime odt = ldt.atOffset( ZoneOffset.UTC ) ;
  24. System.out.println( "odt.toString(): " + odt ) ;
  25.  
  26. long milliseconds = odt.toInstant().toEpochMilli() ;
  27. System.out.println( "milliseconds: " + milliseconds ) ;
  28.  
  29.  
  30. }
  31. }
Success #stdin #stdout 0.2s 39756KB
stdin
Standard input is empty
stdout
ldt.toString: 2020-01-15T14:29
odt.toString(): 2020-01-15T14:29Z
milliseconds: 1579098540000