public static Timestamp stringToTimestamp(final String text) {
    final String s = Objects.requireNonNull(text).trim();
    // Handle simpler cases directly avoiding exceptions
    if (s.length() == DATE_LENGTH) {
      Date d = DateParser.parseDate(s);
      if (d == null) {
        throw new IllegalArgumentException("Cannot parse date: " + text);
      }
      return Timestamp.ofEpochMilli(d.toEpochMilli());
    }
    try {
      return Timestamp.valueOf(s);
    } catch (IllegalArgumentException eT) {
      // Try zoned timestamp
      try {
        return Timestamp.valueOf(
            TimestampTZUtil.parse(s).getZonedDateTime().toLocalDateTime().toString());
      } catch (IllegalArgumentException | DateTimeException eTZ) {
        try {
          // Try HH:mm:ss format (For Hour, Minute & Second UDF).
          return Timestamp.getTimestampFromTime(s);
        } catch(DateTimeException e) {
          // Last attempt
          return Timestamp.ofEpochMilli(Date.valueOf(s).toEpochMilli());
        }
      }
    }
  }
Convert (parse) a String into a Timestamp.

@param text The text to parse
@return The Timestamp parsed from the string
@throws IllegalArgumentException if {@code text} cannot be parsed
@throws NullPointerException if {@code text} is null
common/src/java/org/apache/hadoop/hive/common/type/TimestampUtils.java