Close

Java Date Time - Period.getUnits() Examples

Java Date Time Java Java API 


Class:

java.time.Period

java.lang.Objectjava.lang.Objectjava.time.Periodjava.time.Periodjava.time.chrono.ChronoPeriodChronoPeriodjava.io.SerializableSerializableLogicBig

Method:

public List<TemporalUnit> getUnits()

Returns the set of units supported by this period.


Examples


package com.logicbig.example.period;

import java.time.Period;
import java.time.temporal.TemporalUnit;
import java.util.List;

public class GetUnitsExample {

public static void main(String... args) {
Period p = Period.of(100, 10, 20);
System.out.println(p);

List<TemporalUnit> units = p.getUnits();
System.out.println(units);
}
}

Output

P100Y10M20D
[Years, Months, Days]




See Also