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.  
  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 inputGood = "2015-07-30T09:32:05.543+02:00" ;
  17. String inputBad = "2015-07-35T09:32:05.543+02:00" ;
  18.  
  19. try{
  20. // Good
  21. OffsetDateTime odtGood = OffsetDateTime.parse( inputGood ) ;
  22. System.out.println( "odtGood.toString(): " + odtGood ) ;
  23.  
  24. // Bad
  25. OffsetDateTime odtBad = OffsetDateTime.parse( inputBad ) ;
  26. System.out.println( "odtBad.toString(): " + odtBad ) ;
  27. } catch ( DateTimeParseException e ) {
  28. System.out.println( e ) ;
  29. }
  30.  
  31.  
  32.  
  33. }
  34. }
Success #stdin #stdout 0.14s 4575232KB
stdin
Standard input is empty
stdout
odtGood.toString(): 2015-07-30T09:32:05.543+02:00
java.time.format.DateTimeParseException: Text '2015-07-35T09:32:05.543+02:00' could not be parsed: Invalid value for DayOfMonth (valid values 1 - 28/31): 35