- java.time - Home
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time Package Enums
- java.time - Month
- java.time Useful Resources
- java.time - Discussion
Selected Reading
java.time.Duration.get() Method Example
Description
The java.time.Duration.get() method gets the value of the requested unit.
Declaration
Following is the declaration for java.time.Duration.get() method.
public long get(TemporalUnit unit)
Parameters
unit − the TemporalUnit for which to return the value.
Return Value
the long value of the unit.
Exception
DateTimeException − if the unit is not supported.
UnsupportedTemporalTypeException − if the unit is not supported.
Example
The following example shows the usage of java.time.Duration.get() method.
package com.tutorialspoint;
import java.time.Duration;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
public class DurationDemo {
public static void main(String[] args) {
Duration duration = Duration.between(LocalTime.NOON,LocalTime.MAX);
System.out.println(duration.get(ChronoUnit.SECONDS));
}
}
Let us compile and run the above program, this will produce the following result −
43199
Advertisements