Java Date Time - Period ofYears(int years) example








Period ofYears(int years) creates a Period representing a number of years.

Syntax

ofYears has the following syntax.

public static Period ofYears(int years)

Example

The following example shows how to use ofYears.

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

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

  }
}

The code above generates the following result.