本文整理了Java中java.sql.Timestamp.setNanos()
方法的一些代码示例,展示了Timestamp.setNanos()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.setNanos()
方法的具体详情如下:
包路径:java.sql.Timestamp
类名称:Timestamp
方法名:setNanos
[英]Sets the nanosecond value for this Timestamp.
[中]设置此时间戳的纳秒值。
代码示例来源:origin: apache/flink
private static Timestamp readTimestamp(long time, int nanos) {
Timestamp ts = new Timestamp(time);
ts.setNanos(nanos);
return ts;
}
代码示例来源: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/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: pentaho/pentaho-kettle
protected Timestamp convertIntegerToTimestamp( Long nanos ) {
if ( nanos == null ) {
return null;
}
long msSinceEpoch = nanos / 1000000;
int leftNanos = (int) ( nanos - ( msSinceEpoch * 1000000 ) );
Timestamp timestamp = new Timestamp( msSinceEpoch );
timestamp.setNanos( leftNanos );
return timestamp;
}
代码示例来源: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: apache/hive
public void set(Timestamp t) {
if (t == null) {
timestamp.setTime(0);
timestamp.setNanos(0);
return;
}
timestamp.setTime(t.getTime());
timestamp.setNanos(t.getNanos());
bytesEmpty = true;
timestampEmpty = false;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Returns a JDBC timestamp initialized to the same point in time as {@code this}. */
public java.sql.Timestamp toSqlTimestamp() {
java.sql.Timestamp ts = new java.sql.Timestamp(seconds * 1000);
ts.setNanos(nanos);
return ts;
}
代码示例来源: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/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: apache/flink
@Override
public Timestamp deserialize(DataInputView source) throws IOException {
final long v = source.readLong();
if (v == Long.MIN_VALUE) {
return null;
} else {
final Timestamp t = new Timestamp(v);
t.setNanos(source.readInt());
return t;
}
}
代码示例来源:origin: stackoverflow.com
Date date = parseDateFromFirstPart();
int micros = parseJustLastThreeDigits();
Timestamp ts = new Timestamp(date.getTime());
ts.setNanos(ts.getNanos() + micros * 1000);
代码示例来源: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/incubator-shardingsphere
private Timestamp getTimestamp(final MySQLPacketPayload payload) {
Calendar calendar = Calendar.getInstance();
calendar.set(0, Calendar.JANUARY, 0, payload.readInt1(), payload.readInt1(), payload.readInt1());
Timestamp result = new Timestamp(calendar.getTimeInMillis());
result.setNanos(0);
return result;
}
代码示例来源: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;
}
代码示例来源:origin: apache/hive
@Deprecated
public boolean add(java.sql.Timestamp ts, HiveIntervalYearMonth interval, java.sql.Timestamp result) {
if (ts == null || interval == null) {
return false;
}
// Attempt to match Oracle semantics for timestamp arithmetic,
// where timestamp arithmetic is done in UTC, then converted back to local timezone
long resultMillis = addMonthsToMillis(ts.getTime(), interval.getTotalMonths());
result.setTime(resultMillis);
result.setNanos(ts.getNanos());
return true;
}
代码示例来源:origin: apache/incubator-shardingsphere
private Timestamp getTimestamp(final MySQLPacketPayload payload) {
Calendar calendar = Calendar.getInstance();
calendar.set(0, Calendar.JANUARY, 0, payload.readInt1(), payload.readInt1(), payload.readInt1());
Timestamp result = new Timestamp(calendar.getTimeInMillis());
result.setNanos(0);
return result;
}
代码示例来源: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: apache/hive
@Deprecated
public boolean add(HiveIntervalYearMonth interval, java.sql.Timestamp ts, java.sql.Timestamp result) {
if (ts == null || interval == null) {
return false;
}
long resultMillis = addMonthsToMillis(ts.getTime(), interval.getTotalMonths());
result.setTime(resultMillis);
result.setNanos(ts.getNanos());
return true;
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
public Object fromString(String str) {
final int idxFraction = str.lastIndexOf('.');
int nanos = 0;
if (idxFraction > 0) {
int idx;
for (idx = idxFraction + 1; Character.isDigit(str.charAt(idx)); ++idx)
;
nanos = Integer.parseInt(str.substring(idxFraction + 1, idx));
str = str.substring(0, idxFraction) + str.substring(idx);
}
final Date date = (Date)super.fromString(str);
final Timestamp timestamp = new Timestamp(date.getTime());
timestamp.setNanos(nanos);
return timestamp;
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!