public static Timestamp toTimestamp(String timestampString) {
    try {
      return Timestamp.valueOf(timestampString);
    } catch (Exception e) {
      // Try the next format
    }
    try {
      return new Timestamp(Long.parseLong(timestampString));
    } catch (Exception e) {
    }
    try {
      return Timestamp.from(ZonedDateTime.parse(timestampString, UNIVERSAL_DATE_TIME_FORMATTER).toInstant());
    } catch (Exception e) {
      // Try the next format
    }
    try {
      LocalDateTime dateTime = LocalDateTime.parse(timestampString, UNIVERSAL_DATE_TIME_FORMATTER);
      return Timestamp.valueOf(dateTime);
    } catch (Exception e) {
      throw new IllegalArgumentException(String.format("Invalid timestamp: '%s'", timestampString));
    }
  }
@Test
  public void testValidTimestampFormats() {
    // Test ISO8601 variations with and without milliseconds and timezones
    assertEquals(
        TimestampUtils.toTimestamp("2024-07-12T15:32:36Z"),
        Timestamp.from(LocalDateTime.of(2024, 7, 12, 15, 32, 36).atZone(ZoneOffset.UTC).toInstant()));
    assertEquals(
        TimestampUtils.toTimestamp("2024-07-12 15:32:36.111Z"),
        Timestamp.from(LocalDateTime.of(2024, 7, 12, 15, 32, 36, 111000000).atZone(ZoneOffset.UTC).toInstant()));
    for (int i = 1; i < 7; i++) {
      int fraction = Integer.parseInt("1".repeat(i) + "0".repeat(9 - i));
      assertEquals(
          TimestampUtils.toTimestamp("2024-07-12T15:32:36." + fraction),
          Timestamp.valueOf("2024-07-12 15:32:36." + fraction));
      assertEquals(
          TimestampUtils.toTimestamp("2024-07-12T15:32:36." + fraction + "Z"),
          Timestamp.from(LocalDateTime.of(2024, 7, 12, 15, 32, 36, fraction).atZone(ZoneOffset.UTC).toInstant()));
    }

    // Test date and time variations without 'T'
    assertEquals(TimestampUtils.toTimestamp("2024-07-12 15:32:36.111"), Timestamp.valueOf("2024-07-12 15:32:36.111"));
    assertEquals(TimestampUtils.toTimestamp("2024-07-12 15:32:36"), Timestamp.valueOf("2024-07-12 15:32:36"));
    assertEquals(TimestampUtils.toTimestamp("2024-07-12 15:32"), Timestamp.valueOf("2024-07-12 15:32:00"));
    assertEquals(TimestampUtils.toTimestamp("2024-07-12"), Timestamp.valueOf("2024-07-12 00:00:00"));
    assertEquals(TimestampUtils.toTimestamp("1720798356111"), new Timestamp(1720798356111L));
  }