本文整理了Java中java.time.Duration.getNano()
方法的一些代码示例,展示了Duration.getNano()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.getNano()
方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:getNano
[英]Gets the number of nanoseconds within the second in this duration.
The length of the duration is stored using two fields - seconds and nanoseconds. The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to the length in seconds. The total duration is defined by calling this method and #getSeconds().
A Duration represents a directed distance between two points on the time-line. A negative duration is expressed by the negative sign of the seconds part. A duration of -1 nanosecond is stored as -1 seconds plus 999,999,999 nanoseconds.
[中]获取此持续时间内秒内的纳秒数。
持续时间的长度使用两个字段存储-秒和纳秒。纳秒部分是一个从0到99999999的值,它是对以秒为单位的长度的调整。通过调用此方法和#getSeconds()定义总持续时间。
持续时间表示时间线上两点之间的定向距离。负持续时间由秒部分的负号表示。-1纳秒的持续时间存储为-1秒加9999999纳秒。
代码示例来源:origin: lettuce-io/lettuce-core
private static boolean isExactMinutes(Duration duration) {
return duration.toMillis() % (1000 * 60) == 0 && duration.getNano() == 0;
}
代码示例来源:origin: lettuce-io/lettuce-core
private static boolean isExactSeconds(Duration duration) {
return duration.toMillis() % (1000) == 0 && duration.getNano() == 0;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void writeObject(ObjectOutput output, Duration duration) throws IOException {
output.writeLong(duration.getSeconds());
output.writeInt(duration.getNano());
}
代码示例来源:origin: neo4j/neo4j
public static DurationValue duration( Duration value )
{
requireNonNull( value, "Duration" );
return newDuration( 0, 0, value.getSeconds(), value.getNano() );
}
代码示例来源:origin: hibernate/hibernate-orm
private long getLockWaitTimeoutInSeconds(int timeoutInMilliseconds) {
Duration duration = Duration.ofMillis( timeoutInMilliseconds );
long timeoutInSeconds = duration.getSeconds();
if ( duration.getNano() != 0 ) {
LOG.info( "Changing the query timeout from " + timeoutInMilliseconds + " ms to " + timeoutInSeconds
+ " s, because HANA requires the timeout in seconds" );
}
return timeoutInSeconds;
}
代码示例来源:origin: thinkaurelius/titan
@Override
public void write(WriteBuffer buffer, Duration attribute) {
secondsSerializer.write(buffer,attribute.getSeconds());
nanosSerializer.write(buffer,attribute.getNano());
}
}
代码示例来源:origin: spring-projects/spring-data-redis
private boolean isZeroOrGreater1Second(Duration timeout) {
return timeout.isZero() || timeout.getNano() % TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS) == 0;
}
代码示例来源:origin: JanusGraph/janusgraph
@Override
public void write(WriteBuffer buffer, Duration attribute) {
secondsSerializer.write(buffer,attribute.getSeconds());
nanosSerializer.write(buffer,attribute.getNano());
}
}
代码示例来源:origin: lettuce-io/lettuce-core
private String getQueryString() {
List<String> queryPairs = new ArrayList<>();
if (database != 0) {
queryPairs.add(PARAMETER_NAME_DATABASE + "=" + database);
}
if (clientName != null) {
queryPairs.add(PARAMETER_NAME_CLIENT_NAME + "=" + urlEncode(clientName));
}
if (sentinelMasterId != null) {
queryPairs.add(PARAMETER_NAME_SENTINEL_MASTER_ID + "=" + urlEncode(sentinelMasterId));
}
if (timeout.getSeconds() != DEFAULT_TIMEOUT) {
if (timeout.getNano() == 0) {
queryPairs.add(PARAMETER_NAME_TIMEOUT + "=" + timeout.getSeconds() + toQueryParamUnit(TimeUnit.SECONDS));
} else {
queryPairs.add(PARAMETER_NAME_TIMEOUT + "=" + timeout.toMillis() + toQueryParamUnit(TimeUnit.MILLISECONDS));
}
}
return queryPairs.stream().collect(Collectors.joining("&"));
}
代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310
@Override
public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException
{
if (useTimestamp(provider)) {
if (useNanoseconds(provider)) {
generator.writeNumber(DecimalUtils.toBigDecimal(
duration.getSeconds(), duration.getNano()
));
} else {
generator.writeNumber(duration.toMillis());
}
} else {
// Does not look like we can make any use of DateTimeFormatter here?
generator.writeString(duration.toString());
}
}
代码示例来源:origin: prestodb/presto
@Override
public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException
{
if (useTimestamp(provider)) {
if (useNanoseconds(provider)) {
generator.writeNumber(DecimalUtils.toBigDecimal(
duration.getSeconds(), duration.getNano()
));
} else {
generator.writeNumber(duration.toMillis());
}
} else {
// Does not look like we can make any use of DateTimeFormatter here?
generator.writeString(duration.toString());
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Mono<Boolean> expire(K key, Duration timeout) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(timeout, "Timeout must not be null!");
if (timeout.getNano() == 0) {
return createMono(connection -> connection.keyCommands() //
.expire(rawKey(key), timeout));
}
return createMono(connection -> connection.keyCommands().pExpire(rawKey(key), timeout));
}
代码示例来源:origin: jdbi/jdbi
@Override
public Argument build(Duration duration, ConfigRegistry config) {
Duration d = duration;
final boolean isNegative = d.isNegative();
if (isNegative) {
d = d.negated();
}
final long days = d.toDays();
if (days > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
String.format("duration %s too large to be represented unambiguously as postgres interval",
d));
}
d = d.minusDays(days);
final int hours = (int) d.toHours();
d = d.minusHours(hours);
final int minutes = (int) d.toMinutes();
d = d.minusMinutes(minutes);
if (d.getNano() % 1000 != 0) {
throw new IllegalArgumentException(
String.format("duration %s too precise to represented as postgres interval", d));
}
double seconds = d.getSeconds() + d.getNano() / 1e9;
final PGInterval interval = new PGInterval(0, 0, (int) days, hours, minutes, seconds);
if (isNegative) {
interval.scale(-1);
}
return ObjectArgument.of(interval, Types.OTHER);
}
}
代码示例来源:origin: JanusGraph/janusgraph
timeout.getNano(), methodTime.toString(), partition, idNamespace));
代码示例来源:origin: apache/tinkerpop
@Override
protected ByteBuf writeValue(final Duration value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException {
return allocator.buffer(12).writeLong(value.getSeconds()).writeInt(value.getNano());
}
}
代码示例来源:origin: ebean-orm/ebean
public static BigDecimal toDecimal(Duration instant) {
return new BigDecimal(toDecimal(instant.getSeconds(), instant.getNano()));
}
代码示例来源:origin: pholser/junit-quickcheck
/**
* Gives a random {@code Duration} value, uniformly distributed across the
* interval {@code [min, max]}.
*
* @param min lower bound of the desired interval
* @param max upper bound of the desired interval
* @return a random value
*/
public Duration nextDuration(Duration min, Duration max) {
int comparison = checkRange(Ranges.Type.STRING, min, max);
if (comparison == 0)
return min;
long[] next = nextSecondsAndNanos(
min.getSeconds(),
min.getNano(),
max.getSeconds(),
max.getNano());
return Duration.ofSeconds(next[0], next[1]);
}
代码示例来源:origin: org.jadira.usertype/usertype.core
@Override
public BigInteger toNonNullValue(Duration value) {
return BigInteger.valueOf(value.getNano()).add(BigInteger.valueOf(value.getSeconds()).multiply(NANOS_IN_SECOND));
}
}
代码示例来源:origin: org.jadira.usertype/usertype.core
@Override
public Long toNonNullValue(Duration value) {
BigInteger millisValue = BigInteger.valueOf(value.getNano()).divide(NANOS_IN_MILLI).add(BigInteger.valueOf(value.getSeconds()).multiply(MILLIS_IN_SECOND));
return Long.valueOf(millisValue.longValueExact());
}
}
代码示例来源:origin: com.esotericsoftware/kryo
public void write (Kryo kryo, Output out, Duration duration) {
out.writeLong(duration.getSeconds());
out.writeInt(duration.getNano(), true);
}
内容来源于网络,如有侵权,请联系作者删除!