Period toTotalMonths() example

Description

Period toTotalMonths() gets the total number of months in this period.

Syntax

toTotalMonths has the following syntax.


public long toTotalMonths()

Example

The following example shows how to use toTotalMonths.


import java.time.Period;
/*from w w w . j ava 2s  .  c  o m*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    long l = p.toTotalMonths();
    System.out.println(l);

  }
}

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