OffsetDateTime plus(TemporalAmount amountToAdd) example

Description

OffsetDateTime plus(TemporalAmount amountToAdd) returns a copy of this date-time with the specified amount added.

Syntax

plus has the following syntax.


public OffsetDateTime plus(TemporalAmount amountToAdd)

Example

The following example shows how to use plus.


import java.time.OffsetDateTime;
import java.time.Period;
/*from   w  w  w . j av  a2 s  .c o  m*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.plus(Period.ofDays(2));
    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