fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.time.LocalDate;
  6. import java.time.format.DateTimeFormatter;
  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. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  13. LocalDate ld2 = LocalDate.parse("2016/05/01", formatter);
  14.  
  15. System.out.println("ld2: " + ld2);
  16. }
  17. }
Runtime error #stdin #stdout #stderr 0.25s 320832KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.time.format.DateTimeParseException: Text '2016/05/01' could not be parsed at index 4
	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
	at java.time.LocalDate.parse(LocalDate.java:400)
	at Ideone.main(Main.java:13)