Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime plus(TemporalAmount amountToAdd)
amountToAdd: Period or Duration or user implementation of TemporalAmount.
public OffsetDateTime plus(long amountToAdd, TemporalUnit unit)
unit: e.g. ChronoUnit#DAYS, ChronoUnit#HOURS etc
package com.logicbig.example.offsetdatetime;import java.time.Duration;import java.time.OffsetDateTime;import java.time.Period;import java.time.ZoneOffset;public class PlusExample { public static void main(String... args) { OffsetDateTime d = OffsetDateTime.of(2015, 11, 15, 18, 20, 30, 100, ZoneOffset.ofHours(-6)); OffsetDateTime d2 = d.plus(Period.ofDays(1000)); System.out.println(d2); OffsetDateTime d3 = d.plus(Duration.ofHours(5000)); System.out.println(d3); OffsetDateTime d4 = d.plus(Duration.ofMinutes(-300)); System.out.println(d4); }}
2018-08-11T18:20:30.000000100-06:002016-06-11T02:20:30.000000100-06:002015-11-15T13:20:30.000000100-06:00
package com.logicbig.example.offsetdatetime;import java.time.OffsetDateTime;import java.time.ZoneOffset;import java.time.temporal.ChronoUnit;public class PlusExample2 { public static void main(String... args) { OffsetDateTime d = OffsetDateTime.of(2016, 9, 10, 22, 45, 38, 20000, ZoneOffset.ofHours(-5)); OffsetDateTime d2 = d.plus(2000, ChronoUnit.HALF_DAYS); System.out.println(d2); OffsetDateTime d3 = d.plus(3500, ChronoUnit.HOURS); System.out.println(d3); OffsetDateTime d4 = d.plus(-1000, ChronoUnit.DAYS); System.out.println(d4); }}
2016-12-30T22:45:38.000020-05:002017-02-03T18:45:38.000020-05:002013-12-15T22:45:38.000020-05:00