DateFormatter { public static String formatDate(String date){ SimpleDateFormat parser1 = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat parser2 = new SimpleDateFormat("yyyy-MM-ddX"); Date format; try{ format = parser1.parse(date); return parser1.format(format); } catch(Exception e){} try{ format = parser2.parse(date); return parser1.format(format); }catch(Exception e1){} return date.trim(); }  static String formatDate(String date);  }
@Test public void testDateFormat() { String date = "1993-6-8"; String result = "1993-06-08"; assertTrue(result.equals(DateFormatter.formatDate(date))); date = "1993-13-8"; result = "1994-01-08"; assertTrue(result.equals(DateFormatter.formatDate(date))); date = "1993-10-67"; result = "1993-12-06"; assertTrue(result.equals(DateFormatter.formatDate(date))); }