Java Date Time - Period of(int years, int months, int days) example








Period of(int years, int months, int days) creates a Period representing a number of years, months and days.

Syntax

of has the following syntax.

public static Period of(int years,  int months,  int days)

Example

The following example shows how to use of.

import java.time.Period;
//from  w  w  w. j a v  a 2  s . c  o  m
public class Main {
  public static void main(String[] args) {
    
    Period p = Period.of(2011,12,12);

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

  }
}

The code above generates the following result.