java.time.ZonedDateTime.plusNanos()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(141)

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

ZonedDateTime.plusNanos介绍

[英]Returns a copy of this ZonedDateTime with the specified period in nanoseconds added.

This operates on the instant time-line, such that adding one nano will always be a duration of one nano later. This may cause the local date-time to change by an amount other than one nano. Note that this is a different approach to that used by days, months and years.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并添加指定的时间段(以纳秒为单位)。
这是在即时时间线上进行的,因此添加一个nano之后的持续时间始终为一个nano。这可能会导致本地日期时间的变化量超过一纳诺。请注意,这与日、月和年使用的方法不同。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime plusNanos(long amount) {
  return dt.plusNanos(amount);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public ZonedDateTime plusNanos(long amount) {
  return dt.plusNanos(amount);
}

代码示例来源:origin: net.serenity-bdd/serenity-model

public ZonedDateTime getEndTime() {
  if (startTime == null) { return null; }
  return startTime.plusNanos( duration * 1000);
}

代码示例来源:origin: apache/servicemix-bundles

public ZonedDateTime plusNanos(long amount) {
  return dt.plusNanos(amount);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this {@code ZonedDateTime} with the specified period in nanoseconds subtracted.
 * <p>
 * This operates on the instant time-line, such that subtracting one nano will
 * always be a duration of one nano earlier.
 * This may cause the local date-time to change by an amount other than one nano.
 * Note that this is a different approach to that used by days, months and years.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param nanos  the nanos to subtract, may be negative
 * @return a {@code ZonedDateTime} based on this date-time with the nanoseconds subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public ZonedDateTime minusNanos(long nanos) {
  return (nanos == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1) : plusNanos(-nanos));
}

代码示例来源:origin: nl.vpro.shared/vpro-shared-xml

@Override
  public String marshal(ZonedDateTime value) {
    if (value == null) {
      return null;
    }
    if (value.getNano() == 0 && OMIT_MILLIS_IF_ZERO.get()) {
      return formatterNoMillis.format(value);
    } else {
      return formatter.format(
        // round to millis
        value.plusNanos(500000).truncatedTo(ChronoUnit.MILLIS)
      );
    }
  }
}

代码示例来源:origin: loom/loom-core

@Test
public void constructor_sets_header_properties_correctly() {
  // Arrange
  UUID aggregateId = UUID.randomUUID();
  Random random = new Random();
  long version = random.nextInt(Integer.MAX_VALUE) + 1L;
  ZonedDateTime occurrenceTime = ZonedDateTime.now().plusNanos(random.nextInt());
  // Act
  IssueCreatedForTesting sut = new IssueCreatedForTesting(
      aggregateId, version, occurrenceTime);
  // Assert
  Assert.assertEquals(aggregateId, sut.getAggregateId());
  Assert.assertEquals(version, sut.getVersion());
  Assert.assertEquals(occurrenceTime, sut.getOccurrenceTime());
}

代码示例来源:origin: loom/loom-core

@Test
public void sut_serializes_properties_of_ZonedDateTime_correctly() {
  // Arrange
  Random random = new Random();
  MessageWithZonedDateTimeProperty message = new MessageWithZonedDateTimeProperty(
      ZonedDateTime.now(Clock.systemUTC()).plusNanos(random.nextInt()));
  JacksonMessageSerializer sut = new JacksonMessageSerializer();
  // Act
  String value = sut.serialize(message);
  System.out.println("The serialized value is '" + value + "'.");
  Object actual = sut.deserialize(value);
  // Assert
  Assert.assertNotNull("The actual value is null.", actual);
  Assert.assertTrue(
      "The actual value is not an instance of MessageWithZonedDateTimeProperty.",
      actual instanceof MessageWithZonedDateTimeProperty);
  MessageWithZonedDateTimeProperty actualMessage = (MessageWithZonedDateTimeProperty)actual;
  Assert.assertEquals(
      message.getDateTime().toEpochSecond(),
      actualMessage.getDateTime().toEpochSecond());
}

相关文章

ZonedDateTime类方法