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

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