public static Long getPrimitiveEpoch(Object prim, TimeZone tz) {
    if (prim instanceof java.sql.Timestamp) {
      return ((java.sql.Timestamp) prim).getTime();
    } else if (prim instanceof java.util.Date) {
      return ((java.util.Date) prim).getTime();
    } else {
      try {
        Class<?> dtClazz = Class.forName("org.apache.hadoop.hive.common.type.Date");
        if (prim.getClass() == dtClazz) {
          Method dtGetImpl = dtClazz.getMethod("toEpochMilli");
          return (java.lang.Long) (dtGetImpl.invoke(prim));
        } else {
          Class<?> ttClazz = Class.forName("org.apache.hadoop.hive.common.type.Timestamp");
          if (prim.getClass() == ttClazz) {
            Method ttGetImpl = ttClazz.getMethod("toEpochMilli");
            return (java.lang.Long) (ttGetImpl.invoke(prim));
          } else {
            return null;
          }
        }
      } catch (Exception exc) {
        return null;
      }
    }
  }
Classes o.a.h.h.common.type Date and Timestamp were introduced in Hive-3.1 version.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/shims/HiveShims.java