synchronized void checkDTG() { try { _theDTG = _dateF.parse(_theDate.getText()).getTime(); } catch (final ParseException e) { MWC.GUI.Dialogs.DialogFactory.showMessage( "Date Format Error", "Sorry, date incorrectly formatted (2001/1/21)"); } }
/** * Tries very, very hard to parse the a date. We assume that the text is neither empty nor <code> * null</code>. */ private Date parseDate(String text) { DateFormat formats[] = new DateFormat[] { DateFormat.getDateInstance(DateFormat.SHORT), DateFormat.getDateInstance(DateFormat.MEDIUM), DateFormat.getDateInstance(DateFormat.LONG), DateFormat.getDateInstance(DateFormat.FULL), }; for (int i = 0; i < formats.length; i++) { DateFormat df = formats[i]; try { Date date = df.parse(text); return date; } catch (ParseException ex) { continue; } } error("Could not parse date: " + text); return null; }