Duration getUnits()
gets the set of units supported by this duration.
The supported units are SECONDS, and NANOS. They are returned in the order seconds, nanos.
getUnits
has the following syntax.
public List<TemporalUnit> getUnits()
The following example shows how to use getUnits
.
import java.time.Duration; import java.time.LocalTime; import java.time.temporal.TemporalUnit; import java.util.List; /*w w w . j a v a 2 s . c o m*/ public class Main { public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON); List<TemporalUnit> l = duration.getUnits(); for(TemporalUnit u: l){ System.out.println(u); } } }
The code above generates the following result.