Duration toNanos()
converts this duration to the
total length in nanoseconds expressed as a long.
toNanos
has the following syntax.
public long toNanos()
The following example shows how to use toNanos
.
import java.time.Duration; import java.time.LocalTime; //from w ww .ja v a2s .c om public class Main { public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON); System.out.println(duration.toNanos()); } }
The code above generates the following result.