First question:
new Date(df.parse("09/01/3~34").getTime()); // Produces '09/01/3'
According to DateFormat#parse() JavaDoc:
Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.
Because of that, after it parses the value from the String, it stops searching on it. When it found the ~
sign, it parsed the 3
value to the year and stopped looking on the String.
Second question:
new Date(df.parse("09/01/100000").getTime()); // Produces ' 000-09-01'
It's not producing '000-09-01'. The following code:
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date parsedDate = df.parse("09/01/100000");
System.out.println(parsedDate);
System.out.println(df.format(parsedDate));
Outputs:
Fri Sep 01 00:00:00 BRT 100000
09/01/100000
However, it appears to be a bug with the java.sql.Date#toString
method on JDK. To present this java.sql.Date
correctly, try passing it to your DateFormat#format
method:
java.sql.Date sqlDt = new java.sql.Date(df.parse("09/01/10000").getTime());
System.out.println(df.format(sqlDt));
Output: 09/01/100000