Java Date Time Java Java API
Class:
java.time.LocalTime
Methods:
public LocalTime plus(TemporalAmount amountToAdd)
Returns a new LocalTime instance with the specified amount added to the copy of this local time instance.
The amount provided is typically Duration, Period is not supported by LocalTime.
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.
Examples
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);
} }
Output03:30:50 17:30:50 22: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); } }
Output23:30:50 01:30:50
|