java.sql.Timestamp.getNanos()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中java.sql.Timestamp.getNanos()方法的一些代码示例,展示了Timestamp.getNanos()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.getNanos()方法的具体详情如下:
包路径:java.sql.Timestamp
类名称:Timestamp
方法名:getNanos

Timestamp.getNanos介绍

[英]Gets this Timestamp's nanosecond value
[中]获取此时间戳的纳秒值

代码示例

代码示例来源:origin: apache/flink

private static Timestamp copyTimestamp(Object o) {
  if (o == null) {
    return null;
  } else {
    long millis = ((Timestamp) o).getTime();
    int nanos = ((Timestamp) o).getNanos();
    Timestamp copy = new Timestamp(millis);
    copy.setNanos(nanos);
    return copy;
  }
}

代码示例来源:origin: apache/hive

/**
 * Fill all the vector entries with a timestamp.
 * @param timestamp
 */
public void fill(Timestamp timestamp) {
 isRepeating = true;
 isNull[0] = false;
 time[0] = timestamp.getTime();
 nanos[0] = timestamp.getNanos();
}

代码示例来源:origin: stackoverflow.com

Date date = parseDateFromFirstPart();
int micros = parseJustLastThreeDigits();

Timestamp ts = new Timestamp(date.getTime());
ts.setNanos(ts.getNanos() + micros * 1000);

代码示例来源:origin: apache/hive

/**
 * Set a field from the current value in the scratch timestamp.
 *
 * This is a FAST version that assumes the caller has checked to make sure the current value in
 * the scratch timestamp is valid and elementNum is correctly adjusted for isRepeating.  And,
 * that the isNull entry has been set.  Only the output entry fields will be set by this method.
 *
 * @param elementNum
 */
public void setFromScratchTimestamp(int elementNum) {
 this.time[elementNum] = scratchTimestamp.getTime();
 this.nanos[elementNum] = scratchTimestamp.getNanos();
}

代码示例来源:origin: apache/flink

@Override
public Timestamp copy(Timestamp from) {
  if (from == null) {
    return null;
  }
  final Timestamp t = new Timestamp(from.getTime());
  t.setNanos(from.getNanos());
  return t;
}

代码示例来源:origin: org.codehaus.groovy/groovy

@Deprecated
public static Timestamp plus(Timestamp self, int days) {
  Calendar calendar = Calendar.getInstance();
  calendar.setTime(self);
  calendar.add(Calendar.DATE, days);
  Timestamp ts = new Timestamp(calendar.getTime().getTime());
  ts.setNanos(self.getNanos());
  return ts;
}

代码示例来源:origin: robovm/robovm

/**
 * Tests to see if this timestamp is equal to a supplied timestamp.
 *
 * @param theTimestamp
 *            the timestamp to compare with this {@code Timestamp} object,
 *            passed as an {@code Object}.
 * @return {@code true} if this {@code Timestamp} object is equal to the
 *         supplied {@code Timestamp} object, {@code false} otherwise.
 */
public boolean equals(Timestamp theTimestamp) {
  if (theTimestamp == null) {
    return false;
  }
  return (this.getTime() == theTimestamp.getTime())
      && (this.getNanos() == theTimestamp.getNanos());
}

代码示例来源:origin: apache/flink

@Override
public Timestamp copy(Timestamp from, Timestamp reuse) {
  if (from == null) {
    return null;
  }
  reuse.setTime(from.getTime());
  reuse.setNanos(from.getNanos());
  return reuse;
}

代码示例来源:origin: lealone/Lealone

private static Timestamp dateadd(String part, int count, Timestamp d) {
  int field = getDatePart(part);
  Calendar calendar = Calendar.getInstance();
  int nanos = d.getNanos() % 1000000;
  calendar.setTime(d);
  calendar.add(field, count);
  long t = calendar.getTime().getTime();
  Timestamp ts = new Timestamp(t);
  ts.setNanos(ts.getNanos() + nanos);
  return ts;
}

代码示例来源:origin: dropwizard/dropwizard

@Nullable
  private ZonedDateTime convertToZonedDateTime(Timestamp timestamp) {
    if (timestamp == null) {
      return null;
    }
    final Optional<ZoneId> zoneId = calendar.flatMap(c -> Optional.of(c.getTimeZone().toZoneId()));
    return ZonedDateTime.ofInstant(
      Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getNanos()),
      zoneId.orElse(ZoneId.systemDefault()));
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public Date deepCopyNotNull(Date value) {
    if ( value instanceof Timestamp ) {
      Timestamp orig = (Timestamp) value;
      Timestamp ts = new Timestamp( orig.getTime() );
      ts.setNanos( orig.getNanos() );
      return ts;
    }
    else {
      return new Date( value.getTime() );
    }
  }
}

代码示例来源:origin: apache/ignite

/**
 * @return Value.
 */
public static Timestamp doReadTimestamp(BinaryInputStream in) {
  long time = in.readLong();
  int nanos = in.readInt();
  Timestamp ts = new Timestamp(time);
  ts.setNanos(ts.getNanos() + nanos);
  return ts;
}

代码示例来源:origin: apache/hive

/**
 * Set a field from a Timestamp.
 *
 * This is a FAST version that assumes the caller has checked to make sure elementNum
 * is correctly adjusted for isRepeating.  And, that the isNull entry
 * has been set.  Only the output entry fields will be set by this method.
 *
 * For backward compatibility, this method does check if the timestamp is null and set the
 * isNull entry appropriately.
 *
 * @param elementNum
 * @param timestamp
 */
public void set(int elementNum, Timestamp timestamp) {
 if (timestamp == null) {
  isNull[elementNum] = true;
  noNulls = false;
  return;
 }
 this.time[elementNum] = timestamp.getTime();
 this.nanos[elementNum] = timestamp.getNanos();
}

代码示例来源:origin: apache/hive

@Override
public void assignTimestamp(int index, Timestamp value) {
 // Do not assign the input value object to the timestampValues array element.
 // Always copy value using set* methods.
 timestampValues[index].setTime(value.getTime());
 timestampValues[index].setNanos(value.getNanos());
}

代码示例来源:origin: apache/drill

Timestamp result = Timestamp.valueOf(dateFormat.format(fromTs));
if (inputTs.getNanos() != 0) {
 result.setNanos(inputTs.getNanos());

代码示例来源:origin: dropwizard/dropwizard

@Nullable
  private OffsetDateTime convertToOffsetDateTime(Timestamp timestamp) {
    if (timestamp == null) {
      return null;
    }
    final Optional<ZoneId> zoneId = calendar.flatMap(c -> Optional.of(c.getTimeZone().toZoneId()));
    return OffsetDateTime.ofInstant(
      Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getNanos()),
      zoneId.orElse(ZoneId.systemDefault()));
  }
}

代码示例来源:origin: apache/hive

@Override
public void assignNullTimestamp(int keyIndex, int index) {
 isNull[keyIndex] = true;
 // assign 0 to simplify hashcode
 timestampValues[index].setTime(ZERO_TIMESTAMP.getTime());
 timestampValues[index].setNanos(ZERO_TIMESTAMP.getNanos());
}

代码示例来源:origin: alibaba/canal

Timestamp ts = new Timestamp(millisDeserialized);
  int nanosDeserialized = decodeUnsignedInt(b, Bytes.SIZEOF_LONG);
  ts.setNanos(nanosDeserialized < 1000000 ? ts.getNanos() + nanosDeserialized : nanosDeserialized);
  v = ts;
} else if (phType == PhType.UNSIGNED_TIME || phType == PhType.UNSIGNED_DATE) {
  Timestamp ts = new Timestamp(millisDeserialized);
  int nanosDeserialized = decodeUnsignedInt(b, Bytes.SIZEOF_LONG);
  ts.setNanos(nanosDeserialized < 1000000 ? ts.getNanos() + nanosDeserialized : nanosDeserialized);
  v = ts;
} else if (phType == PhType.VARBINARY) {

代码示例来源:origin: apache/hive

/**
 * Return a double representation of a Timestamp.
 * @param timestamp
 * @return
 */
public static double getDouble(Timestamp timestamp) {
 // Same algorithm as TimestampWritable (not currently import-able here).
 double seconds, nanos;
 seconds = millisToSeconds(timestamp.getTime());
 nanos = timestamp.getNanos();
 return seconds + nanos / 1000000000;
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public Object cloneValueData( Object object ) throws KettleValueException {
 Timestamp timestamp = getTimestamp( object );
 if ( timestamp == null ) {
  return null;
 }
 Timestamp clone = new Timestamp( timestamp.getTime() );
 clone.setNanos( timestamp.getNanos() );
 return clone;
}

相关文章