public static Timestamp doubleToTimestamp(double f) {
    try {
      long seconds = (long) f;

      // We must ensure the exactness of the double's fractional portion.
      // 0.6 as the fraction part will be converted to 0.59999... and
      // significantly reduce the savings from binary serialization
      BigDecimal bd = new BigDecimal(String.valueOf(f));

      bd = bd.subtract(new BigDecimal(seconds)).multiply(new BigDecimal(1000000000));
      int nanos = bd.intValue();

      // Convert to millis
      long millis = seconds * 1000;
      if (nanos < 0) {
        millis -= 1000;
        nanos += 1000000000;
      }
      Timestamp t = new Timestamp(millis);

      // Set remaining fractional portion to nanos
      t.setNanos(nanos);
      return t;
    } catch (NumberFormatException nfe) {
      return null;
    } catch (IllegalArgumentException iae) {
      return null;
    }
  }
Convert the timestamp to a double measured in seconds.
@return double representation of the timestamp, accurate to nanoseconds
storage-api/src/java/org/apache/hadoop/hive/ql/util/TimestampUtils.java