public static synchronized Date stringToDate(String dateString) throws ParseException {
    if (dateString.length() == 4) {
      return YEAR_FORMAT.parse(dateString);
    } else if (dateString.length() == 6) {
      return MONTH_FORMAT.parse(dateString);
    } else if (dateString.length() == 8) {
      return DAY_FORMAT.parse(dateString);
    } else if (dateString.length() == 10) {
      return HOUR_FORMAT.parse(dateString);
    } else if (dateString.length() == 12) {
      return MINUTE_FORMAT.parse(dateString);
    } else if (dateString.length() == 14) {
      return SECOND_FORMAT.parse(dateString);
    } else if (dateString.length() == 17) {
      return MILLISECOND_FORMAT.parse(dateString);
    }
    throw new ParseException("Input is not valid date string: " + dateString, 0);
  }