Duration toNanos() example

Description

Duration toNanos() converts this duration to the total length in nanoseconds expressed as a long.

Syntax

toNanos has the following syntax.


public long toNanos()

Example

The following example shows how to use toNanos.


import java.time.Duration;
import java.time.LocalTime;
/*from ww w  . j av a2 s  .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.





















Home »
  Java Date Time »
    java.time Reference »




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