Java Date Time - Period toTotalMonths() example








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;
// w  ww .j a v a 2 s  .co 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.