SimpleDateFormat parse(string str) doesn’t throw an exception when str = 2011/12/12aaaaaaaaa?

The JavaDoc on parse(…) states the following: parsing does not necessarily use all characters up to the end of the string It seems like you can’t make SimpleDateFormat throw an exception, but you can do the following: SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/d”); sdf.setLenient(false); ParsePosition p = new ParsePosition( 0 ); String t1 = “2011/12/12aaa”; System.out.println(sdf.parse(t1,p)); … Read more

java.text.ParseException: Unparseable date

Your pattern does not correspond to the input string at all… It is not surprising that it does not work. This would probably work better: SimpleDateFormat sdf = new SimpleDateFormat(“EE MMM dd HH:mm:ss z yyyy”, Locale.ENGLISH); Then to print with your required format you need a second SimpleDateFormat: Date parsedDate = sdf.parse(date); SimpleDateFormat print = … Read more