ZonedDateTime plus(long amountToAdd, TemporalUnit unit) example

Description

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

Syntax

plus has the following syntax.


public ZonedDateTime plus(long amountToAdd,   TemporalUnit unit)

Example

The following example shows how to use plus.


import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
// w ww . j  a  v a 2  s .  com
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.plus(12,ChronoUnit.YEARS);
    System.out.println(n);
  } 
}

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