fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. import java.time.*;
  9. import java.time.temporal.*;
  10. import java.time.format.*;
  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.  
  19. String input = "Mon, 13 Mar 2017 19:00:10 +0530 (IST)";
  20. int index = input.indexOf ( " (" ); // Note we are including the SPACE before the LEFT PARENTHESIS as we want to delete both characters.
  21. String inputModified = input.substring ( 0 , index );
  22.  
  23.  
  24. DateTimeFormatter f = DateTimeFormatter.ofPattern( "EEE, d MMM uuuu HH:mm:ss Z" );
  25. OffsetDateTime odt = OffsetDateTime.parse ( inputModified , f );
  26.  
  27. Instant instant = odt.toInstant ();
  28.  
  29. System.out.println ("inputModified: " + inputModified );
  30. System.out.println ("odt.toString(): " + odt );
  31. System.out.println ("instant.toString(): " + instant );
  32.  
  33. }
  34. }
Success #stdin #stdout 0.16s 4386816KB
stdin
Standard input is empty
stdout
inputModified: Mon, 13 Mar 2017 19:00:10 +0530
odt.toString(): 2017-03-13T19:00:10+05:30
instant.toString(): 2017-03-13T13:30:10Z