Java Date Time Java Java API
java.time.LocalTime
public LocalTime plus(TemporalAmount amountToAdd)
Returns a new LocalTime instance with the specified amount added to the copy of this local time instance.
LocalTime
The amount provided is typically Duration, Period is not supported by LocalTime.
public LocalTime plus(long amountToAdd, TemporalUnit unit)
public LocalTime plus(long amountToAdd,
TemporalUnit unit)
This method returns a new instance of LocalTime, with the provided amount, per provided unit, added to the copy this instance.
package com.logicbig.example.localtime;import java.time.Duration;import java.time.LocalTime;public class PlusExample { public static void main (String... args) { LocalTime d1 = LocalTime.of(22, 30, 50); LocalTime d2 = d1.plus(Duration.ofHours(5)); System.out.println(d2); d2 = d1.plus(Duration.ofHours(-5)); System.out.println(d2); d2 = d1.plus(Duration.ofDays(2)); System.out.println(d2); }}
03:30:5017:30:5022:30:50
package com.logicbig.example.localtime;import java.time.LocalTime;import java.time.temporal.ChronoUnit;public class PlusExample2 { public static void main (String... args) { LocalTime d1 = LocalTime.of(12, 30, 50); LocalTime d2 = d1.plus(11, ChronoUnit.HOURS); System.out.println(d2); d2 = d1.plus(-11, ChronoUnit.HOURS); System.out.println(d2); }}
23:30:5001:30:50