/** * Returns the specified date as ISO 8601 format. * * @param date the specified date. * @return the date formatted using ISO 8601. * * @throws ParseException Should an error be thrown by the {@link SimpleDateFormat#parse(String)} method. */ public static Date parseAuto(String date) throws ParseException { if (date.length() == 4 && date.matches("\\d{4}")) return YEAR.parse(date); if (date.indexOf('W') == 6) return WEEK_DATE.parse(date); if (date.length() == 10) return CALENDAR_DATE.parse(date); if (date.length() == 8) return TIME.parse(date); return DATETIME.parse(date); }