Returns a new copy of this OffsetTime with specified TemporalAmount added to it.
Returns a new copy of this OffsetTime with specified long amount added to the specified unit (e.g. ChronoUnit#DAYS, ChronoUnit#HOURS etc).
package com.logicbig.example.offsettime;
import java.time.Duration;
import java.time.OffsetTime;
public class PlusExample {
public static void main(String... args) {
OffsetTime t1 = OffsetTime.now();
System.out.println(t1);
OffsetTime t2 = t1.plus(Duration.ofMinutes(30));
System.out.println(t2);
OffsetTime t3 = t1.plus(Duration.parse("PT6H3M20S"));
System.out.println(t3);
}
}
Output
16:13:28.645-05:00
16:43:28.645-05:00
22:16:48.645-05:00
package com.logicbig.example.offsettime;
import java.time.OffsetTime;
import java.time.temporal.ChronoUnit;
public class PlusExample2 {
public static void main(String... args) {
OffsetTime t = OffsetTime.now();
System.out.println(t);
for (ChronoUnit u : ChronoUnit.values()) {
try {
OffsetTime t2 = t.plus(2, u);
System.out.printf("Plus 2 %8s unit: %s%n", u, t2);
} catch (Exception e) {
System.out.printf("plus not supported for unit: %10s%n", u.name());
}
}
}
}
Output
16:13:30.655-05:00
Plus 2 Nanos unit: 16:13:30.655000002-05:00
Plus 2 Micros unit: 16:13:30.655002-05:00
Plus 2 Millis unit: 16:13:30.657-05:00
Plus 2 Seconds unit: 16:13:32.655-05:00
Plus 2 Minutes unit: 16:15:30.655-05:00
Plus 2 Hours unit: 18:13:30.655-05:00
Plus 2 HalfDays unit: 16:13:30.655-05:00
plus not supported for unit: DAYS
plus not supported for unit: WEEKS
plus not supported for unit: MONTHS
plus not supported for unit: YEARS
plus not supported for unit: DECADES
plus not supported for unit: CENTURIES
plus not supported for unit: MILLENNIA
plus not supported for unit: ERAS
plus not supported for unit: FOREVER