Java Date Time - Period withYears(int years) example








Period withYears(int years) returns a copy of this period with the specified amount of years.

Syntax

withYears has the following syntax.

public Period withYears(int years)

Example

The following example shows how to use withYears.

import java.time.Period;
/*from w  ww .  ja v  a  2s . c  o m*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    Period l = p.withYears(10);
    System.out.println(l);

  }
}

The code above generates the following result.