Java LocalTime plusHours() Method
Example
Add 3 hours and 12 hours to a time:
import java.time.LocalTime;
public class Main {
public static void main(String[] args) {
LocalTime myTime = LocalTime.of(14, 30);
System.out.println(myTime.plusHours(3));
System.out.println(myTime.plusHours(12));
}
}
Definition and Usage
The plusHours() method returns a new time, a number of hours after the original time. The original time is not changed.
The time goes around midnight, like a clock: 14:30 plus 12 hours is 02:30.
Tip: Use the plusMinutes() method to add minutes.
Syntax
public LocalTime plusHours(long hoursToAdd)
Parameter Values
| Parameter | Description |
|---|---|
| hoursToAdd | Required. The number of hours to add. It can be negative. |
Technical Details
| Returns: | A new LocalTime object with the hours added. |
|---|
Related Pages
❮ Date and Time Methods