Period plusYears(long yearsToAdd) example

Description

Period plusYears(long yearsToAdd) returns a copy of this period with the specified years added.

Syntax

plusYears has the following syntax.


public Period plusYears(long yearsToAdd)

Example

The following example shows how to use plusYears.


import java.time.Period;
//w ww .  j  a  v a 2 s  .c o m
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    Period l = p.plusYears(12);
    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