public static Date valueOf(final String text) {
    String trimedText = Objects.requireNonNull(text).trim();
    ParsePosition pos = new ParsePosition(0);
    try {
      TemporalAccessor t = PARSE_FORMATTER.parse(trimedText, pos);
      if (pos.getErrorIndex() >= 0) {
        throw new DateTimeParseException("Text could not be parsed to date", trimedText, pos.getErrorIndex());
      }
      //Check if there is still text left after parsing
      if(pos.getIndex() < trimedText.length()) {
        char lastChar = trimedText.charAt(pos.getIndex());
        //Check if the first character of the remaining is a digit, e.g. "2023-08-0800" if yes, then it is a parse error and must throw an exception
        if (lastChar >= '0' && lastChar <= '9'){
          throw new DateTimeParseException("Text '" + trimedText + "' could not be parsed, unparsed text found at index " + pos.getIndex(), trimedText,
              pos.getIndex());
        }
      }  
      return new Date(LocalDate.of(t.get(YEAR), t.get(MONTH_OF_YEAR), t.get(DAY_OF_MONTH)));
    } catch (DateTimeException e) {
      throw new IllegalArgumentException("Cannot create date, parsing error");
    }
  }
Obtains an instance of Date from a text string such as 2021-02-22T09:39:27.
Other supported formats are "2021-02-22T09:39:27Z", "2021-02-22 09:39:27",
"2021-02-22T09:39:27+00:00", "2021-02-22". Any time information is simply
dropped.

@param text the text to parse, not null
@return The {@code Date} objects parsed from the text
@throws IllegalArgumentException if the text cannot be parsed into a
          {@code Date}
@throws NullPointerException if {@code text} is null
common/src/java/org/apache/hadoop/hive/common/type/Date.java