Period ofMonths(int months) example

Description

Period ofMonths(int months) creates a Period representing a number of months.

Syntax

ofMonths has the following syntax.


public static Period ofMonths(int months)

Example

The following example shows how to use ofMonths.


import java.time.Period;
/* w w w  .  j a va  2 s. c  o  m*/
public class Main {
  public static void main(String[] args) {
    
    Period p = Period.ofMonths(12);

    System.out.println(p.toString());

  }
}

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