fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.time.*;
  6. import java.time.format.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. System.out.println (isDateValid("12/10/2021"));
  15. }
  16.  
  17. static boolean isDateValid(String date) {
  18. try {
  19. DateTimeFormatter formatter = DateTimeFormatter
  20. .ofPattern("dd/MM/uuuu")
  21. .withResolverStyle(ResolverStyle.STRICT);
  22. LocalDate.parse(date, formatter);
  23. return true;
  24. } catch (DateTimeException ex) {
  25. ex.printStackTrace();
  26. return false;
  27. }
  28. }
  29. }
Success #stdin #stdout 0.08s 49172KB
stdin
Standard input is empty
stdout
true