Duration withNanos(int nanoOfSecond) example

Description

Duration withNanos(int nanoOfSecond) returns a copy of this duration with the specified nano-of-second.

Syntax

withNanos has the following syntax.


public Duration withNanos(int nanoOfSecond)

Example

The following example shows how to use withNanos.


import java.time.Duration;
import java.time.LocalTime;
//w ww .  j  av  a  2s.co m
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    duration = duration.withNanos(1000);
    System.out.println(duration.getNano());

  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset