Period getUnits() example

Description

Period getUnits() gets the set of units supported by this period.

The supported units are YEARS, MONTHS and DAYS.

Syntax

getUnits has the following syntax.


public List<TemporalUnit> getUnits()

Example

The following example shows how to use getUnits.


import java.time.Period;
//from ww  w .  j av  a 2s .co  m
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    System.out.println(p.getUnits());

  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset