Java Date Time - OffsetDateTime plus(long amountToAdd, TemporalUnit unit) example








OffsetDateTime plus(long amountToAdd, TemporalUnit unit) returns a copy of this date-time with the specified amount added.

Syntax

plus has the following syntax.

public OffsetDateTime plus(long amountToAdd,   TemporalUnit unit)

Example

The following example shows how to use plus.

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
//w w  w  .  j  ava2  s. c  o m
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.plus(20,ChronoUnit.HOURS);
    System.out.println(d);
  }
}

The code above generates the following result.