TL; dr
When using java.time, input with this formatting pattern fails, as you would expect.
LocalDate .parse( "02-03-04" , DateTimeFormatter.ofPattern ( "uuuu-Md" ) )
... throws java.time.format.DateTimeParseException
java.time
The classes you use are now superseded by the modern java.time classes defined in JSR 310 and built into Java 8 and later.
The LocalDate class represents a value only for a date without a time of day and without a time zone or offset from UTC .
Define a custom formatting template as you requested. Use the DateTimeFormatter class.
DateTimeFormatter f = DateTimeFormatter.ofPattern ( "uuuu-Md" );
Try to analyze your data.
String input = "02-03-04"; LocalDate localDate = LocalDate.parse ( input , f );
We encountered a DateTimeParseException that failed in a missing century of input year. As you expected.
Exception in thread "main" java.time.format.DateTimeParseException: text '02 -03-04 'cannot be parsed with index 0
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the problematic old obsolete date and time classes such as java.util.Date , Calendar and & SimpleDateFormat .
To learn more, check out the Oracle Tutorial . And look in Kara for many examples and explanations. Specification: JSR 310 .
The Joda-Time project, which is now in maintenance mode, recommends switching to java.time classes.
You can exchange java.time objects directly with your database. Use a JDBC driver compatible with JDBC 4.2 or later. No need for strings, no need for java.sql.* Classes.
Where to get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a testing ground for possible future additions to java.time. Here you can find some useful classes, such as Interval , YearWeek , YearQuarter and more .