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. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. try{
  13. String date1 = String.valueOf(java.time.LocalDate.of(1998,01,11));
  14. System.out.println(date1);
  15. java.time.format.DateTimeFormatter inputFormatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd");
  16. java.time.LocalDateTime ldt = java.time.LocalDateTime.parse(date1, inputFormatter);
  17. // java.time.ZonedDateTime zdt = java.time.ZonedDateTime.parse("22/01/1998", inputFormatter);
  18. System.out.println(ldt);
  19. } catch(Exception ex) {
  20. System.out.println("error" + ex);
  21. }
  22.  
  23. }
  24. }
Success #stdin #stdout 0.14s 58676KB
stdin
Standard input is empty
stdout
1998-01-11
errorjava.time.format.DateTimeParseException: Text '1998-01-11' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 1998-01-11 of type java.time.format.Parsed