Duration get(TemporalUnit unit)
gets the value of the requested unit.
This returns a value for each of the two supported units, SECONDS and NANOS. All other units throw an exception.
get
has the following syntax.
public long get(TemporalUnit unit)
The following example shows how to use get
.
import java.time.Duration; import java.time.LocalTime; import java.time.temporal.ChronoUnit; /*from w ww .j a va 2 s . c om*/ public class Main { public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON); System.out.println(duration.get(ChronoUnit.SECONDS)); } }
The code above generates the following result.