OffsetDateTime plusYears(long years) example

Description

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;
/*from  w  w  w  .j  a  v a 2 s  . c  o  m*/
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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset