Duration minusNanos(long nanosToSubtract) example

Description

Duration minusNanos(long nanosToSubtract) returns a copy of this duration with the specified duration in nanoseconds subtracted.

Syntax

minusNanos has the following syntax.


public Duration minusNanos(long nanosToSubtract)

Example

The following example shows how to use minusNanos.


import java.time.Duration;
import java.time.LocalTime;
//from  w w  w. j  a  v  a 2s  . c o m
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.getNano());
    duration = duration.minusNanos(3);
    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