public static void setTimeWritable(Object twHive, long epoch) {
    try {                                // Hive 3.1 and above
      Class<?> ttClazz = Class.forName("org.apache.hadoop.hive.common.type.Timestamp");
      Class<?> twClazz = Class.forName("org.apache.hadoop.hive.serde2.io.TimestampWritableV2");
      Method ttSetImpl = ttClazz.getMethod("setTimeInMillis", long.class);
      Method twSetImpl = twClazz.getMethod("set", ttClazz);
      Object ttObj = ttClazz.getConstructor().newInstance();
      ttSetImpl.invoke(ttObj, epoch);
      twSetImpl.invoke(twHive, ttObj);
    } catch (Exception e1) {
      try {                            // Hive 0.12 and above
        Class<?> twClazz = Class.forName("org.apache.hadoop.hive.serde2.io.TimestampWritable");
        Method twSetImpl = twClazz.getMethod("set", java.sql.Timestamp.class);
        twSetImpl.invoke(twHive, new java.sql.Timestamp(epoch));
      } catch (Exception e2) {              // Hive 0.11 and below
        // column type TIMESTAMP not supported
        throw new UnsupportedOperationException("TIMESTAMP type");
      }
    }
  }
Type TIMESTAMP was introduced in Hive-0.12 - class TimestampWritable in API.
Class TimestampWritableV2 is used instead as of Hive-3.1 version.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/shims/HiveShims.java