Uses of Class
java.time.Duration

Packages that useDuration
Package
Description
java.lang
Provides classes that are fundamental to the design of the Java programming language.
java.net.http
HTTP Client and WebSocket APIs
java.time
The main API for dates, times, instants, and durations.
java.time.temporal
Access to date and time using fields and units, and date time adjusters.
java.time.zone
Support for time-zones and their rules.
java.util.concurrent
Utility classes commonly useful in concurrent programming.
jdk.jfr
This package provides classes to create events and control Flight Recorder.
jdk.jfr.consumer
This package contains classes for consuming Flight Recorder data.
jdk.management.jfr
This package contains classes to control and monitor Flight Recorder over Java Management Extensions (JMX).
  • Uses ofDuration injava.lang

    Methods injava.lang that return types with arguments of typeDuration
    Modifier and Type
    Method
    Description
    ProcessHandle.Info.totalCpuDuration()
    Returns the total cputime accumulated of the process.
    Methods injava.lang with parameters of typeDuration
    Modifier and Type
    Method
    Description
    final boolean
    Thread.join(Duration duration)
    Waits for this thread to terminate for up to the given waiting duration.
    static void
    Thread.sleep(Duration duration)
    Causes the currently executing thread to sleep (temporarily cease execution) for the specified duration, subject to the precision and accuracy of system timers and schedulers.
    boolean
    Process.waitFor(Duration duration)
    Causes the current thread to wait, if necessary, until the process represented by thisProcess object has terminated, or the specified waiting duration elapses.
  • Uses ofDuration injava.net.http

    Methods injava.net.http that return types with arguments of typeDuration
    Modifier and Type
    Method
    Description
    HttpClient.connectTimeout()
    Returns anOptional containing theconnect timeout duration for this client.
    HttpRequest.timeout()
    Returns anOptional containing this request's timeout duration.
    Methods injava.net.http with parameters of typeDuration
    Modifier and Type
    Method
    Description
    boolean
    HttpClient.awaitTermination(Duration duration)
    Blocks until all operations have completed execution after a shutdown request, or theduration elapses, or the current thread isinterrupted, whichever happens first.
    HttpClient.Builder.connectTimeout(Duration duration)
    Sets the connect timeout duration for this client.
    WebSocket.Builder.connectTimeout(Duration timeout)
    Sets a timeout for establishing a WebSocket connection.
    HttpRequest.Builder.timeout(Duration duration)
    Sets a timeout for this request.
  • Uses ofDuration injava.time

    Classes injava.time that implement interfaces with type arguments of typeDuration
    Modifier and Type
    Class
    Description
    final class 
    A time-based amount of time, such as '34.5 seconds'.
    Fields injava.time declared asDuration
    Modifier and Type
    Field
    Description
    static finalDuration
    Duration.ZERO
    Constant for a duration of zero.
    Methods injava.time that returnDuration
    Modifier and Type
    Method
    Description
    Duration.abs()
    Returns a copy of this duration with a positive length.
    staticDuration
    Duration.between(Temporal startInclusive,Temporal endExclusive)
    Obtains aDuration representing the duration between two temporal objects.
    Duration.dividedBy(long divisor)
    Returns a copy of this duration divided by the specified value.
    staticDuration
    Duration.from(TemporalAmount amount)
    Obtains an instance ofDuration from a temporal amount.
    Duration.minus(long amountToSubtract,TemporalUnit unit)
    Returns a copy of this duration with the specified duration subtracted.
    Duration.minus(Duration duration)
    Returns a copy of this duration with the specified duration subtracted.
    Duration.minusDays(long daysToSubtract)
    Returns a copy of this duration with the specified duration in standard 24 hour days subtracted.
    Duration.minusHours(long hoursToSubtract)
    Returns a copy of this duration with the specified duration in hours subtracted.
    Duration.minusMillis(long millisToSubtract)
    Returns a copy of this duration with the specified duration in milliseconds subtracted.
    Duration.minusMinutes(long minutesToSubtract)
    Returns a copy of this duration with the specified duration in minutes subtracted.
    Duration.minusNanos(long nanosToSubtract)
    Returns a copy of this duration with the specified duration in nanoseconds subtracted.
    Duration.minusSeconds(long secondsToSubtract)
    Returns a copy of this duration with the specified duration in seconds subtracted.
    Duration.multipliedBy(long multiplicand)
    Returns a copy of this duration multiplied by the scalar.
    Duration.negated()
    Returns a copy of this duration with the length negated.
    staticDuration
    Duration.of(long amount,TemporalUnit unit)
    Obtains aDuration representing an amount in the specified unit.
    staticDuration
    Duration.ofDays(long days)
    Obtains aDuration representing a number of standard 24 hour days.
    staticDuration
    Duration.ofHours(long hours)
    Obtains aDuration representing a number of standard hours.
    staticDuration
    Duration.ofMillis(long millis)
    Obtains aDuration representing a number of milliseconds.
    staticDuration
    Duration.ofMinutes(long minutes)
    Obtains aDuration representing a number of standard minutes.
    staticDuration
    Duration.ofNanos(long nanos)
    Obtains aDuration representing a number of nanoseconds.
    staticDuration
    Duration.ofSeconds(long seconds)
    Obtains aDuration representing a number of seconds.
    staticDuration
    Duration.ofSeconds(long seconds, long nanoAdjustment)
    Obtains aDuration representing a number of seconds and an adjustment in nanoseconds.
    staticDuration
    Duration.parse(CharSequence text)
    Obtains aDuration from a text string such asPnDTnHnMn.nS.
    Duration.plus(long amountToAdd,TemporalUnit unit)
    Returns a copy of this duration with the specified duration added.
    Duration.plus(Duration duration)
    Returns a copy of this duration with the specified duration added.
    Duration.plusDays(long daysToAdd)
    Returns a copy of this duration with the specified duration in standard 24 hour days added.
    Duration.plusHours(long hoursToAdd)
    Returns a copy of this duration with the specified duration in hours added.
    Duration.plusMillis(long millisToAdd)
    Returns a copy of this duration with the specified duration in milliseconds added.
    Duration.plusMinutes(long minutesToAdd)
    Returns a copy of this duration with the specified duration in minutes added.
    Duration.plusNanos(long nanosToAdd)
    Returns a copy of this duration with the specified duration in nanoseconds added.
    Duration.plusSeconds(long secondsToAdd)
    Returns a copy of this duration with the specified duration in seconds added.
    Duration.truncatedTo(TemporalUnit unit)
    Returns a copy of thisDuration truncated to the specified unit.
    Instant.until(Instant endExclusive)
    Calculates theDuration until anotherInstant.
    Duration.withNanos(int nanoOfSecond)
    Returns a copy of this duration with the specified nano-of-second.
    Duration.withSeconds(long seconds)
    Returns a copy of this duration with the specified amount of seconds.
    Methods injava.time with parameters of typeDuration
    Modifier and Type
    Method
    Description
    int
    Duration.compareTo(Duration otherDuration)
    Compares this duration to the specifiedDuration.
    long
    Duration.dividedBy(Duration divisor)
    Returns number of whole times a specified Duration occurs within this Duration.
    Duration.minus(Duration duration)
    Returns a copy of this duration with the specified duration subtracted.
    staticClock
    Clock.offset(Clock baseClock,Duration offsetDuration)
    Obtains a clock that returns instants from the specified clock with the specified duration added.
    InstantSource.offset(InstantSource baseSource,Duration offsetDuration)
    Obtains a source that returns instants from the specified source with the specified duration added.
    Duration.plus(Duration duration)
    Returns a copy of this duration with the specified duration added.
    staticClock
    Clock.tick(Clock baseClock,Duration tickDuration)
    Obtains a clock that returns instants from the specified clock truncated to the nearest occurrence of the specified duration.
    InstantSource.tick(InstantSource baseSource,Duration tickDuration)
    Obtains a source that returns instants from the specified source truncated to the nearest occurrence of the specified duration.
  • Uses ofDuration injava.time.temporal

    Methods injava.time.temporal that returnDuration
    Modifier and Type
    Method
    Description
    ChronoUnit.getDuration()
    Gets the estimated duration of this unit in the ISO calendar system.
    TemporalUnit.getDuration()
    Gets the duration of this unit, which may be an estimate.
  • Uses ofDuration injava.time.zone

    Methods injava.time.zone that returnDuration
    Modifier and Type
    Method
    Description
    ZoneRules.getDaylightSavings(Instant instant)
    Gets the amount of daylight savings in use for the specified instant in this zone.
    ZoneOffsetTransition.getDuration()
    Gets the duration of the transition.
  • Uses ofDuration injava.util.concurrent

    Methods injava.util.concurrent with parameters of typeDuration
    Modifier and Type
    Method
    Description
    long
    TimeUnit.convert(Duration duration)
    Converts the given time duration to this unit.
  • Uses ofDuration injdk.jfr

    Methods injdk.jfr that returnDuration
    Modifier and Type
    Method
    Description
    Recording.getDuration()
    Returns the specified duration for this recording, ornull if no duration is set.
    Recording.getMaxAge()
    Returns the length of time that the data is kept in the disk repository before it is removed.
    Methods injdk.jfr with parameters of typeDuration
    Modifier and Type
    Method
    Description
    void
    Recording.scheduleStart(Duration delay)
    Starts this recording after a delay.
    void
    Recording.setDuration(Duration duration)
    Sets a duration for how long a recording runs before it stops.
    void
    Recording.setMaxAge(Duration maxAge)
    Determines how far back data is kept in the disk repository.
    EventSettings.withPeriod(Duration duration)
    Sets the interval for the event that is associated with this event setting.
    EventSettings.withThreshold(Duration duration)
    Sets the threshold for the event that is associated with this event setting.
  • Uses ofDuration injdk.jfr.consumer

    Methods injdk.jfr.consumer that returnDuration
    Modifier and Type
    Method
    Description
    RecordedEvent.getDuration()
    Returns the duration of the event, measured in nanoseconds.
    RecordedObject.getDuration(String name)
    Returns the value of a timespan field.
    Methods injdk.jfr.consumer with parameters of typeDuration
    Modifier and Type
    Method
    Description
    void
    EventStream.awaitTermination(Duration timeout)
    Blocks until all actions are completed, or the stream is closed, or the timeout occurs, or the current thread is interrupted, whichever happens first.
    void
    RecordingStream.awaitTermination(Duration timeout)
     
    void
    RecordingStream.setMaxAge(Duration maxAge)
    Determines how far back data is kept for the stream.
  • Uses ofDuration injdk.management.jfr

    Methods injdk.management.jfr with parameters of typeDuration
    Modifier and Type
    Method
    Description
    void
    RemoteRecordingStream.awaitTermination(Duration timeout)
     
    void
    RemoteRecordingStream.setMaxAge(Duration maxAge)
    Determines how far back data is kept for the stream.