Duration withNanos(int nanoOfSecond)
returns a copy of
this duration with the specified nano-of-second.
withNanos
has the following syntax.
public Duration withNanos(int nanoOfSecond)
The following example shows how to use withNanos
.
import java.time.Duration; import java.time.LocalTime; //from www . ja va 2 s.c o 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.