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 input = "2017-02-45" ;
  17. System.out.println( "input: " + input ) ;
  18.  
  19. for( ResolverStyle rs : ResolverStyle.values() )
  20. {
  21. try{
  22. System.out.println( "---------------" ) ;
  23. System.out.println( "Parsing with ResolverStyle: " + rs ) ;
  24. DateTimeFormatter f = DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle( rs ) ;
  25. LocalDate ld = LocalDate.parse( input , f ) ;
  26. System.out.println( "ld.toString(): " + ld ) ;
  27. } catch ( DateTimeParseException e ) {
  28. System.out.println( "Caught exception for ResolverStyle: " + rs ) ;
  29. }
  30.  
  31. }
  32.  
  33. }
  34. }
Success #stdin #stdout 0.13s 4386816KB
stdin
Standard input is empty
stdout
input: 2017-02-45
---------------
Parsing with ResolverStyle: STRICT
Caught exception for ResolverStyle: STRICT
---------------
Parsing with ResolverStyle: SMART
Caught exception for ResolverStyle: SMART
---------------
Parsing with ResolverStyle: LENIENT
ld.toString(): 2017-03-17