Period getMonths() example

Description

Period getMonths() gets the amount of months of this period. This returns the months unit.

Syntax

getMonths has the following syntax.


public int getMonths()

Example

The following example shows how to use getMonths.


import java.time.Period;
/* w  w  w . j a v  a2 s . com*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    System.out.println(p.getMonths());

  }
}

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