Java Date Time - OffsetDateTime plusYears(long years) example








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

Syntax

plusYears has the following syntax.

public OffsetDateTime plusYears(long years)

Example

The following example shows how to use plusYears.

import java.time.OffsetDateTime;

public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.plusYears(20);
    System.out.println(d);
  }
}

The code above generates the following result.