getUnits()
is an instance method of the Period
class used to retrieve all the units supported by the Period
class. The units supported by the Period
class are as follows:
The getUnits()
method is defined in the Period
class. The Period
class is defined in the java.time
package. To import the Period
class check the following import statement.
import java.time.Period;
public List<TemporalUnit> getUnits()
The method has no parameters.
This method returns a list of units supported by the Period
class.
import java.time.Period;public class Main{public static void main(String[] args) {int numMonths = 0;int numYears = 0;int numDays = 0;Period period = Period.of(numYears, numMonths, numDays);System.out.printf("The supported units of the %s is %s\n", period, period.getUnits());}}